Page 1 of 1 1
Topic Options
#210264 - 2015-05-13 08:43 PM How read XML with duplicate node names?
Valentim Offline
Fresh Scripter

Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
how can I do to read two tags with the same name in an XML file?

XML example
 Quote:
<site>
<name>Google< /name>
<link>www.google.com< /link>
< /site>

<site>
<name>Yahoo< /name>
<link>www.yahoo.com< /link>
< /site>



Kix code:
 Code:
Dim $objXML            ; object to hold the xml document
Dim $objNnode          ; xml node object

$objXML  = CreateObject("Msxml2.DOMDocument.6.0")

$=$objXML.load("file.xml")
$=$objXML.setProperty( "SelectionLanguage", "XPath")

$objSite1 = $objXML.selectSingleNode("/site/name")
$objLink1 = $objXML.selectSingleNode("/site/link")
; $objSite2 = $objXML.selectSingleNode("/site/name") ; how read second name?
; $objLink2 = $objXML.selectSingleNode("/site/link") ; how read second link?


someone could help me?


Edited by Glenn Barnas (2015-05-14 12:56 PM)
Edit Reason: XML freaking out the Code Formatter
_________________________

Top
#210265 - 2015-05-14 01:32 PM Re: How read XML with duplicate node names? [Re: Valentim]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
I think you want the selectNodes method. It will return all matches as a list.
Top
#210272 - 2015-05-18 03:40 PM Re: How read XML with duplicate node names? [Re: BradV]
Valentim Offline
Fresh Scripter

Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
I tried using selectnode, but is not working.

 Code:
$NodeList = $objXML.selectNodes("site/name")
For Each $Node In $NodeList
   ? $Node.text
Next


and

 Code:
$objNodeList = $objXML.selectNodes("site/name")
For $i = 0 To $objNodeList.length - 1
  ? $objNodeList.item($i).Text
Next


when file has two equal nodes, file is not read.

example:

 Code:
:Begin File1.xml
<site>
  <name>Google< /name>
  <link>www.google.com< /link>
< /site>
:End File1

:Begin File2.xml
<site>
  <name>Google< /name>
  <link>www.google.com< /link>
< /site>

<site>
  <name>Yahoo< /name>
  <link>www.yahoo.com< /link>
< /site>
:End File2


file1 displays "Google", file2 does not show anything
_________________________

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 515 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.05 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org