DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Retreiving Element Attributes Only

  1. #1
    Craig Guest

    Retreiving Element Attributes Only


    Hi

    I have an xml document shown below...

    <btaconfig>
    <initiator-addresses>
    <address name="address1" component="address1">
    <sending>
    <transport-binding name="MSMQ/>
    </sending>
    <receiving/>
    </address>
    <initiator-addresses>
    <btaconfig>

    Using MSXML 3.0 In want to return only the attributes in the xml doxument.
    i.e. I should return

    nodeName nodeValue
    -------- ---------
    name address1
    component address1
    name MSMQ

    I have been trying all sorts of combinations of
    Set nodeList = DOM.selectNodes("//initiator-addresses/address/@*")
    which only returns the attributes for address, not address and transport
    binding.

    Any help on the syntax would be greatly appreciated.

    Craig

  2. #2
    Russell Jones Guest

    Re: Retreiving Element Attributes Only

    I hope you typed your XML rather than copying it, because it contains
    numerous errors. That aside, the syntax you're looking for is:
    selectNodes("btaconfig//@*").

    Here's an example--error-trapped so you can see the load errors if they
    occur on your real file.

    Dim xml As New DOMDocument
    Dim atts As IXMLDOMNodeList
    Dim att As IXMLDOMAttribute
    If Not xml.Load("yourDrive:\yourPath\yourfile.xml") Then
    Debug.Print xml.parseError.reason, xml.parseError.line
    Else
    Set atts = xml.selectNodes("btaconfig//@*")
    For Each att In atts
    Debug.Print att.Name, att.Text
    Next
    End If

    Russell Jones
    Sr. Web Development Editor
    DevX.com

    "Craig" <pearson@ozy.dec.com> wrote in message
    news:3a7f6185$1@news.devx.com...
    >
    > Hi
    >
    > I have an xml document shown below...
    >
    > <btaconfig>
    > <initiator-addresses>
    > <address name="address1" component="address1">
    > <sending>
    > <transport-binding name="MSMQ/>
    > </sending>
    > <receiving/>
    > </address>
    > <initiator-addresses>
    > <btaconfig>
    >
    > Using MSXML 3.0 In want to return only the attributes in the xml doxument.
    > i.e. I should return
    >
    > nodeName nodeValue
    > -------- ---------
    > name address1
    > component address1
    > name MSMQ
    >
    > I have been trying all sorts of combinations of
    > Set nodeList = DOM.selectNodes("//initiator-addresses/address/@*")
    > which only returns the attributes for address, not address and transport
    > binding.
    >
    > Any help on the syntax would be greatly appreciated.
    >
    > Craig




  3. #3
    Craig Guest

    Re: Retreiving Element Attributes Only


    For retrieve attributes within a specific child element of the parent (including
    the parent) you can use, in the case of this example

    //initiator-addresses/address//@*

    ><btaconfig>
    > <initiator-addresses>
    > <address name="address1" component="address1">
    > <sending>
    > <transport-binding name="MSMQ/>
    > </sending>
    > <receiving/>
    > </address>
    > <transport name="name" component="./cioconfig">
    > <sending>
    > <transport-binding name="MSMQ/>
    > </sending>
    > <receiving/>
    > </transport>
    > <initiator-addresses>
    ><btaconfig>






    "Craig" <pearson@ozy.dec.com> wrote:
    >
    >Hi
    >
    >I have an xml document shown below...
    >
    ><btaconfig>
    > <initiator-addresses>
    > <address name="address1" component="address1">
    > <sending>
    > <transport-binding name="MSMQ/>
    > </sending>
    > <receiving/>
    > </address>
    > <initiator-addresses>
    ><btaconfig>
    >
    >Using MSXML 3.0 In want to return only the attributes in the xml doxument.
    > i.e. I should return
    >
    >nodeName nodeValue
    >-------- ---------
    >name address1
    >component address1
    >name MSMQ
    >
    >I have been trying all sorts of combinations of
    >Set nodeList = DOM.selectNodes("//initiator-addresses/address/@*")
    >which only returns the attributes for address, not address and transport
    >binding.
    >
    >Any help on the syntax would be greatly appreciated.
    >
    >Craig



  4. #4
    Tim Coulter Guest

    Re: Retreiving Element Attributes Only


    Craig,

    The syntax you require is:

    Set nodeList = DOM.selectNodes("//@*")

    This means "starting from the tree root, select all attributes at all levels".

    By the way, The XML in your sample wasn't well formed. The corrected version
    is:

    <btaconfig>
    <initiator-addresses>
    <address name="address1" component="address1">
    <sending>
    <transport-binding name="MSMQ"/>
    </sending>
    <receiving/>
    </address>
    </initiator-addresses>
    </btaconfig>

    Best regards,
    Tim Coulter


    "Craig" <pearson@ozy.dec.com> wrote:
    >
    >Hi
    >
    >I have an xml document shown below...
    >
    ><btaconfig>
    > <initiator-addresses>
    > <address name="address1" component="address1">
    > <sending>
    > <transport-binding name="MSMQ/>
    > </sending>
    > <receiving/>
    > </address>
    > <initiator-addresses>
    ><btaconfig>
    >
    >Using MSXML 3.0 In want to return only the attributes in the xml doxument.
    > i.e. I should return
    >
    >nodeName nodeValue
    >-------- ---------
    >name address1
    >component address1
    >name MSMQ
    >
    >I have been trying all sorts of combinations of
    >Set nodeList = DOM.selectNodes("//initiator-addresses/address/@*")
    >which only returns the attributes for address, not address and transport
    >binding.
    >
    >Any help on the syntax would be greatly appreciated.
    >
    >Craig



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center