Solved

ASP to load a XML and insert into database

Posted on 2001-09-10
3
214 Views
Last Modified: 2013-11-19
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>
=========
0
Comment
Question by:slok
  • 2
3 Comments
 
LVL 4

Expert Comment

by:chabaud
ID: 6474589
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
0
 
LVL 3

Author Comment

by:slok
ID: 6474796
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"
0
 
LVL 4

Accepted Solution

by:
chabaud earned 100 total points
ID: 6474822
Try enumerator like this :

var e, child;

e = new Enumerator(root.childNodes);   //Create Enumerator.
for (;!e.atEnd();e.moveNext())          
{
  child = e.item();

  Response.Write(child.text + "<br>");
}
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now