Solved

ASP to load a XML and insert into database

Posted on 2001-09-10
3
215 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

863 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

27 Experts available now in Live!

Get 1:1 Help Now