Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP to load a XML and insert into database

Posted on 2001-09-10
3
Medium Priority
?
222 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 400 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
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…

715 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