Link to home
Start Free TrialLog in
Avatar of slok
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\Project1
and I have the XML file in
C:\InetPub\wwwroot\Project1\admin\imports

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>
=========
Avatar of chabaud
chabaud

To load your Xml file, with a validation against a DTD ou Schema, try something like this:

Dim xmlDoc
Set xmlDoc = CreateObject("Msxml2.DOMDocument")

'Load Xml file
xmlDoc.async = False
xmlDoc.validateOnParse = True
xmlDoc.Load "admin\imports\yourfile.xml"

'Display Parsing Error
If xmlDoc.parseError.errorCode Then
     Response.Write "<b>You have error " & Hex( xmlDoc.parseError.errorCode) & ": " & xmlDoc.parseError.reason & "</b>"
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
Avatar of slok

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"
ASKER CERTIFIED SOLUTION
Avatar of chabaud
chabaud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial