This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > March 2005 > Need help with XML Dom
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Need help with XML Dom
|
|
|
| Hi,
I am trying to implement something where i read a XML into a XMLDOM object
and then look for specific elements inside the root element. I read an
attribute of that element and then within that element try to look for
another specific element and process that.
The problem i am facing is the selectNodes in the inner loop is getting all
the ClientLog elements in the doc. What I want here is to get the child
elements only for that particular node.
Set doc = Server.CreateObject("MSXML.DOMDocument")
doc.load(resultXmlFileLocation)
doc.setProperty "SelectionLanguage", "XPath"
If Len(namespaceSetting) > 0 then
doc.setProperty "SelectionNamespaces", namespaceSetting
End if
Set root = doc
'Set selectedElems = root.selectNodes("//s1:ScriptTestResult")
Dim selectedElems
Set selectedElems = root.GetElementsByTagName("ScriptTestResult")
Dim logElements
For i=0 to (selectedElems.length - 1)
Set attr1 = selectedElems.item(i).GetAttributeNode("envName")
envName = attr1.value
set logElements =
selectedElems.item(i).selectNodes("//s2:ClientLog")
<% =envName %><br /><% = logElements.length %><br />
I have this code as a part of a ASP script. Any help is truely appreciated.
Thanks,
Rajesh
| |
| Derek Harmon 2005-03-16, 4:23 am |
| "Kals" <Kals@discussions.microsoft.com> wrote in message news:228B6E4D-0AFC-4860-B1D7-81E66CE9E8D0@microsoft.com...
> The problem i am facing is the selectNodes in the inner loop is getting all
> the ClientLog elements in the doc. What I want here is to get the child
> elements only for that particular node.
: :
> selectedElems.item(i).selectNodes("//s2:ClientLog")
Rajesh,
The "//" at the start of the XPath expression means get all child elements
from the root of the document throughout (the so-called descendant or
self axis). The fix should be just to remove the "//" which gives you,
set logElements = selectedElems.item(i).selectNodes("s2:ClientLog")
The child axis is the default, so it will get only the immediate children of
the context node.
Derek Harmon
| |
|
| Thanks Derek, that worked.
I was thinking that in the context of the node, the node will be treated as
a separate XML doc and so was using the "//".
On a side note the elements that I was trying to look for were not the
immediate childs so the query that I used now is "*/*/s2:Clientlog"
Thanks,
Rajesh
"Derek Harmon" wrote:
> "Kals" <Kals@discussions.microsoft.com> wrote in message news:228B6E4D-0AFC-4860-B1D7-81E66CE9E8D0@microsoft.com...
> : :
>
> Rajesh,
>
> The "//" at the start of the XPath expression means get all child elements
> from the root of the document throughout (the so-called descendant or
> self axis). The fix should be just to remove the "//" which gives you,
>
> set logElements = selectedElems.item(i).selectNodes("s2:ClientLog")
>
> The child axis is the default, so it will get only the immediate children of
> the context node.
>
>
> Derek Harmon
>
>
>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|