Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2003, 08:35 AM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP not reading all XML tags!

I have an XML document such as this one:

<Calls>
  <Call>
     <ID>93434</ID>
     <FirstName>John</FirstName>
     <LastName>Frank</LastName>
     <Phone>555-555-5555</Phone>
     <Country />
  </Call>
</Calls>

The problem is when the object Microsoft.XMLDOM trys to read the <Country /> tag, it gets an error. Below is the code that I use to read through the XML:
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.load Session("XmlResponseFile")
Set objLst = objXML.getElementsByTagName("Call")
    For i = 0 to objLst.Length - 1
        Set subLst = objLst.item(i)
        sCallNumber = subLst.childNodes(0)


Anyone have any ideas why I get the following error???

Error Message:
Microsoft VBScript runtime error '800a01a8'
Object required: 'subLst.childNodes(...).childNodes(...)'

/jstars/call_list.asp, line 42
 
Old June 27th, 2003, 03:57 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Have you given us the correct code? Seems very unlikely that this code gives the error stated.
You should also try to avoid that prog id. Use a more modern one:

Set objXML = Server.CreateObject("Msxml2.DomDocument.3.0")

or if version 4 is available

Set objXML = Server.CreateObject("Msxml2.DomDocument.4.0")

Only use the one you had for the very old parser versions.



--

Joe
 
Old July 1st, 2003, 09:13 AM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the xml I loaded:

<XML>
  <Calls>
     <Call>
        <ClientCode>ABICOC</ClientCode>
        <CallNumber>9234848</CallNumber>
        <DateTime>200305151127</DateTime>
        <WhoCalled></WhoCalled>
        <Priority>IMP</Priority>
        <OpenClosed>OPEN</OpenClosed>
     </Call>
     <Call>
        <ClientCode>ABICOC</ClientCode>
        <CallNumber>9234848</CallNumber>
        <DateTime>200305151127</DateTime>
        <WhoCalled>Jeff M</WhoCalled>
        <Priority>IMP</Priority>
        <OpenClosed>OPEN</OpenClosed>
     </Call>
  </Calls>
</xml>

The Code I am using to parse this is:
Dim objXML
Set objXML = Server.CreateObject("Msxml2.DomDocument.4.0")
objXML.async = False
objXML.load Session("XmlResponseFile")
if objXML.parseError.errorcode <> 0 then
    response.write "Reason: " & objXML.parseError.reason
    response.write "<br>"
    response.write "<br>"
    response.write "The Line: " & objXML.parseError.srcText
else
    Dim i
    Set objLst = objXML.getElementsByTagName("Call")
    For i = 0 to objLst.Length - 1
    Set subLst = objLst.item(i)
    sClientCode = subLst.childNodes(0).childNodes(0).Text
    sCallNumber = subLst.childNodes(1).childNodes(0).Text
    sDateTime = subLst.childNodes(2).childNodes(0).Text
    sWhoCalled = subLst.childNodes(3).childNodes(0).Text
    sPriority = subLst.childNodes(4).childNodes(0).Text
    sOpenClosed= subLst.childNodes(5).childNodes(0).Text



The problem is when there is no text for the tag <WhoCalled> it puts in <WhoCalled /> and that's where I am getting the error. When there is no open AND closed tag.
 
Old July 1st, 2003, 10:16 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Personally I'd select the child nodes using XPath (subLst.selectSingleNode("ClientCode").Text) but if you wish to stick with your approach the second call to childNodes is redundant.
Instead of:
sClientCode = subLst.childNodes(0).childNodes(0).Text
try:
sClientCode = subLst.childNodes(0).Text


--

Joe
 
Old July 4th, 2003, 01:43 AM
Authorized User
 
Join Date: Jun 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What you need to do is catch the exception, or check for a null value before making an assignment. Try something like:

If subList.childNodes.Count > 0 Then
  sCallNumber = subLst.childNodes(0)
End If

Or,

If Not IsNull(subList.childNodes(0)) Then
  sCallNumber = subLst.childNodes(0)
End If

I haven't checked the syntax I'm just going off the top of my head but you get the idea. You could even just change the program that generates the XML so it does not include tags that have no value.

Just a few ideas, hope they help.

Skin





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading XML through ASP jeffm_22 Classic ASP XML 3 June 11th, 2010 07:02 AM
Reading XML file using ASP itHighway Classic ASP XML 1 June 7th, 2006 06:16 AM
Reading XML file using ASP itHighway XSLT 2 April 29th, 2006 04:52 AM
Reading XML string using asp itHighway Classic ASP XML 2 March 10th, 2005 11:54 PM
Reading XML from ASP texasraven Classic ASP XML 2 February 26th, 2004 03:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.