Solved

ASP to load a XML and insert into database

Posted on 2001-09-10
3
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

624 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