Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP 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 January 19th, 2005, 03:58 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default access sub nodes using XMLDOM

Hi! I have an XML file which has this node:

<ROOT>
 <TEST>
  <D0>000000000000000.00</D0>
  <D1>000000000000000.00</D1>
  <D2 />
  <D3 />
  <D4 />
  <D5 />
  <D6 />
  <D7 />
 </TEST>
</ROOT>

I need to access the values of D0 and D1. I came up with this code:
        Dim xml
    Set xml = Server.CreateObject("Microsoft.XMLDOM")
    xml.async = False
    xml.load (Server.MapPath("sample.xml"))

        Dim test
    test = xml.getElementsByTagName("TEST").item(0).text
    Set xml = Nothing

I am able to get this: 000000000000000.00 000000000000000.00

But this is not what I need. I need to get the values separately (i.e. array or something). How do I do this?
 
Old January 19th, 2005, 05:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can be more precise by using selectNodes or selectSingleNode methods, combined with XPath selection.

xml.selectSingleNode("/ROOT/TEST/D0").text gives value of the D0

xml.selectNodes("/ROOT/TEST/*") gives you a nodelist object containing all elements D0...D7 - u can use this like an array by accessing items by index number or using For Each varChildNode in theNodeList

Finally Microsoft.XMLDOM is very old version. Try one of these later versions instead:
MSXML2.DOMDocument.4.0
MSXML2.DOMDocument.3.0

hth
Phil
 
Old January 19th, 2005, 09:43 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What are the requirements of MSXML2.DOMDocument.4.0/MSXML2.DOMDocument.3.0? msxml3.dll/msxml3.dll right? are these built in components? or do you have to install it first?

thanks for your help phil! i already found a solution...thanks again!

set test = xml.getElementsByTagName("test")
Set xml = Nothing

dim objChild
For Each objChild In test

if objChild.hasChildNodes() then
    do while (i<objChild.childNodes.length and flag=0)
        if objChild.childNodes(i).text="" then
            flag=1
        else
            response.write i&"-"
            response.write objChild.childNodes(i).text
        end if
        i=i+1
    loop
end if





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pogramming the XmlDOM in C# sencee C# 5 March 10th, 2006 11:09 AM
XMLDOM problem braindog_43 Javascript How-To 2 January 16th, 2005 01:54 PM
XMLDOM problem braindog_43 XML 2 January 16th, 2005 01:38 PM
ASP3 / XMLDOM / updating nodes -- HELP PLEASE Michael Yevdokimov XML 1 January 3rd, 2005 12:37 PM
ASP3 / XMLDOM / updating nodes -- HELP PLEASE Michael Yevdokimov Classic ASP XML 0 December 30th, 2004 11:59 AM





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