slok
asked on
ASP to load a XML and insert into database
I'm using ASP and have the database and webserver on the
same server.
I have a loadXM.asp file which is at
C:\InetPub\wwwroot\Project 1
and I have the XML file in
C:\InetPub\wwwroot\Project 1\admin\im ports
1. How can I load the XML file and parse it for validation?
ie loadXML.asp
2. After validation, I would like to get the data within
each node and display it on the response page?
Below is a sample of my XML file.
==========
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<category>
<name2>????????????Chinese Test
</name2>
<Name1>Test Category.</Name1>
<Name>1</Name>
<extendedAttributes/>
</category>
</catalog>
=========
same server.
I have a loadXM.asp file which is at
C:\InetPub\wwwroot\Project
and I have the XML file in
C:\InetPub\wwwroot\Project
1. How can I load the XML file and parse it for validation?
ie loadXML.asp
2. After validation, I would like to get the data within
each node and display it on the response page?
Below is a sample of my XML file.
==========
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<category>
<name2>????????????Chinese
</name2>
<Name1>Test Category.</Name1>
<Name>1</Name>
<extendedAttributes/>
</category>
</catalog>
=========
ASKER
ok, I manage to do the load.
I'm trying to move around the XML node using JScript.
//Set root to the XML document's root element, COLLECTION:
var root = dom.documentElement;
//Walk from the root to each of its child nodes:
for(child in root.childNodes) {
Response.Write(child.text + "<br>");
}
however, I face an error.
==
Microsoft JScript runtime error '800a01bd'
Object doesn't support this action
loadXML.asp, line 30
====
it complains at the the "for loop"
I'm trying to move around the XML node using JScript.
//Set root to the XML document's root element, COLLECTION:
var root = dom.documentElement;
//Walk from the root to each of its child nodes:
for(child in root.childNodes) {
Response.Write(child.text + "<br>");
}
however, I face an error.
==
Microsoft JScript runtime error '800a01bd'
Object doesn't support this action
loadXML.asp, line 30
====
it complains at the the "for loop"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim xmlDoc
Set xmlDoc = CreateObject("Msxml2.DOMDo
'Load Xml file
xmlDoc.async = False
xmlDoc.validateOnParse = True
xmlDoc.Load "admin\imports\yourfile.xm
'Display Parsing Error
If xmlDoc.parseError.errorCod
Response.Write "<b>You have error " & Hex( xmlDoc.parseError.errorCod
Else
Response.Write "<b>Xml ok</b>"
End if
Then your could move around Xml node using the DOM or you can transform it to Html using an Xsl stylesheet.
hth