Hi,
I have recently followed the a tutorial on Kirupa.com to search an XML file:
http://www.kirupa.com/web/xml/examples/searchbestof.htm
I am trying to edit it so when looping the XML file is performed, it goes down a level in other words the tutorials XML is based like this:
[COLOR=red]<?xml version=“1.0” ?>
<bestof url="[/COLOR][COLOR=red]http://www.kirupaforum.com/forums/forumdisplay.php?f=12[/COLOR][COLOR=red]">
<post url="[/COLOR][COLOR=red]http://www.kirupaforum.com/forums/showthread.php?t=43216[/COLOR][COLOR=red]">
<title>xml menu DONE :)</title>
<author>hga77</author>
<message>
<![CDATA[Happy New Year kirupa ]]>
</message>
</post>[/COLOR]
[COLOR=red] <post url="[/COLOR][COLOR=red]http://www.kirupaforum.com/forums/showthread.php?t=43216[/COLOR][COLOR=red]">
<title>xml menu DONE :)</title>
<author>hga77</author>
<message>
<![CDATA[Happy New Year kirupa ]]>
</message>
</post>[/COLOR]
and mine like this:
[COLOR=red]<?xml version=“1.0” ?>
<bestof url="[/COLOR][COLOR=red]http://www.kirupaforum.com/forums/forumdisplay.php?f=12[/COLOR][COLOR=red]">
<post url="[/COLOR][COLOR=red]http://www.kirupaforum.com/forums/showthread.php?t=43216[/COLOR][COLOR=red]">
<title>[/COLOR]
[COLOR=red] <message>
<![CDATA[Happy New Year kirupa ]]>
</message>[/COLOR]
[COLOR=red] </title>
</post>[/COLOR]
[COLOR=red] <post url="[/COLOR][COLOR=red]http://www.kirupaforum.com/forums/showthread.php?t=43216[/COLOR][COLOR=red]">
<title>[/COLOR]
[COLOR=red] <message>
<![CDATA[Happy New Year kirupa ]]>
</message>[/COLOR]
[COLOR=red] </title>
</post>[/COLOR]
So I want to go firstChild.firstChild rather than firstChild.
The loop code is as follows:
[COLOR=#000050]SearchXML[/COLOR] [COLOR=#0000ff]=[/COLOR] [COLOR=#006610]function[/COLOR][COLOR=#0000ff]([/COLOR][COLOR=#000050]nodes[/COLOR], [COLOR=#000050]query[/COLOR], [COLOR=#000050]useChildElements[/COLOR][COLOR=#0000ff]){[/COLOR] [COLOR=#006610]var[/COLOR] [COLOR=#000050]results[/COLOR] [COLOR=#0000ff]=[/COLOR] [COLOR=#0000ff][][/COLOR]; [COLOR=#006610]for[/COLOR] [COLOR=#0000ff]([/COLOR][COLOR=#006610]var[/COLOR] [COLOR=#000050]i[/COLOR][COLOR=#0000ff]=[/COLOR][COLOR=#991010]0[/COLOR]; [COLOR=#000050]i[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#000050]nodes[/COLOR].[COLOR=#0000d0]length[/COLOR]; [COLOR=#000050]i[/COLOR][COLOR=#0000ff]++){[/COLOR] [COLOR=#006610]for[/COLOR] [COLOR=#0000ff]([/COLOR][COLOR=#006610]var[/COLOR] [COLOR=#000050]j[/COLOR][COLOR=#0000ff]=[/COLOR][COLOR=#991010]0[/COLOR]; [COLOR=#000050]j[/COLOR][COLOR=#0000ff]<[/COLOR][COLOR=#000050]nodes[/COLOR][COLOR=#0000ff][[/COLOR][COLOR=#000050]i[/COLOR][COLOR=#0000ff]][/COLOR].[COLOR=#0000d0]childNodes[/COLOR].[COLOR=#0000d0]length[/COLOR]; [COLOR=#000050]j[/COLOR][COLOR=#0000ff]++){[/COLOR] [COLOR=#000050]currNode[/COLOR] [COLOR=#0000ff]=[/COLOR] [COLOR=#000050]nodes[/COLOR][COLOR=#0000ff][[/COLOR][COLOR=#000050]i[/COLOR][COLOR=#0000ff]][/COLOR].[COLOR=#0000d0]childNodes[/COLOR][COLOR=#0000ff][[/COLOR][COLOR=#000050]j[/COLOR][COLOR=#0000ff]][/COLOR]; [COLOR=#006610]if[/COLOR] [COLOR=#0000ff]([/COLOR][COLOR=#000050]useChildElements[/COLOR].[COLOR=#000050]contains [/COLOR]COLOR=#0000ff){[/COLOR] [COLOR=#006610]if[/COLOR] COLOR=#0000ff{[/COLOR] [COLOR=#000050]results[/COLOR].[COLOR=#0000d0]push[/COLOR]COLOR=#0000ff[/COLOR]; [COLOR=#000050]break[/COLOR];[COLOR=#0000ff]}[/COLOR][COLOR=#0000ff]}[/COLOR][COLOR=#0000ff]}[/COLOR][COLOR=#0000ff]}[/COLOR] [COLOR=#006610]return[/COLOR] [COLOR=#000050]results[/COLOR];[COLOR=#0000ff]}[/COLOR][COLOR=#0000ff][/COLOR] [COLOR=black]I believe the answer may be editing this part but I cannot work out where? If anyone has any solution I would appreciate it.[/COLOR]
Cheers
Chris