Jump to content

XML - where does it end?


tbresson

Recommended Posts

Hi.I'm trying to make a small script that parses through an XML file. I don't have a lot of experience with XML but I managed to create a script (ASP) where I can access the contents of the XML file like this:

Set objXML = Server.CreateObject("Microsoft.XMLDOM")objXML.async = false  objXML.load(source)	Set objLst = objXML.getElementsByTagName("*")For i = 0 to (objLst.length-1)select case objLst.item(i).nodeName	' CODE HEREend selectSet objXML = nothing

Now. The content of the XML apparently does not contain blank nodes if the values are non-existing. Like this: (Madonna doesn't have a lastname (lname)).

<person> <fname>Allan</fname> <lname>Rogers</lname> <fname>Madonna</fname> <fname>Peter</fname> <lname>Smith</lname></person>

While looping through the content of the XML file I want to know when I have a complete set of information about ONE person, and the use that information to select against a database to compare info.But I can't tell when a new persons info. ends if the last node is not the same everytime.So I tried looking for fname, if I hit fname that meant that all info. had been gathered about ONE person. But then the last "unit" wouldn't get collected since there's no <fname> before </person>. For that I tried finding some sort of EOF property for XML but didn't suceeded. I did try using objLst.length to determine if I was at the end of the XML file, but apparently it doesn't take the very last node with it.If my code is placed in the top of the code around the first tag, it doesn't reach the last nodes and if the code is placed after collecting all nodes I can't look the next new "person" by fname.Perhaps I'm doing this all wrong, so I'd appreciate if someone have any ideas on how to proceed.

Link to comment
Share on other sites

Why don't you group all the things in the XML file and access them separatly. Example:

<people><person><fname>Allan</fname><lname>Rogers</lname></person><person><fname>Madonna</fname></person><person><fname>Peter</fname><lname>Smith</lname></person></people>

Link to comment
Share on other sites

I've solved the problemIf anyone wants to know:Before the loop I did this:NewEntry = falseFirstLine = trueThe very first entry of the XML file is called "fname":select case objLst.item(i).nodeName case "fname" if FirstLine = false then NewEntry = true end if FirstLine = falseAfter the end select I did this:if (i = objLst.length-1) then NewEntry = trueend ifif NewEntry = true then ' a whole "unit" of the XML file is not collected -> do stuff NewEntry = falseend if

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...