| Author |
Xpath - selectSingleNode -[starts-with??`
|
|
| Dave F. 2007-09-30, 6:20 pm |
| Hi
Is there away to use starts-with with selectSingleNode?
I have am XML file of lots of random numbers:
<Offset>
<Dist>
<x>1</x>
<x>33</x>
<x>202.5</x>
etc...
etc...
</Dist>
</Offset>
I'm using vb(a) & this works:
Dim NodeLst As IXMLDOMNodeList
OffsetNo = 2
Set NodeLst = MsDom.selectNodes("/Offset/Dist/x[starts-with(.,'" &
OffsetNo & "')]")
But i'd like to use selectSingleNode so I can place the result in a
Listbox using this sort of routine:
Set Child = NodeLst.firstChild
While Not Child Is Nothing
LstBxRecent.AddItem Child.Text
Set Child = Child.nextSibling
Wend
Is this possible? If so please help me out because I'm stuck.
Thanks
Dave F.
| |
| TOUDIdel 2007-10-01, 3:16 am |
|
Uzytkownik "Dave F." <df@maaf.cu.uk> napisal w wiadomosci
news:u7Fjmj6AIHA.5868@TK2MSFTNGP05.phx.gbl...
> Is there away to use starts-with with selectSingleNode?
Generally all XPath functions work in selectNodes() method, but sometimes
(e.g. JScript) you have to set special property:
xmldom.setProperty('SelectionLanguage','XPath')
--
td
| |
| Martin Honnen 2007-10-01, 6:16 pm |
| Dave F. wrote:
> Is there away to use starts-with with selectSingleNode?
Yes, but with MSXML 3 you need to set
MsDom.setProperty "SelectionLanguage", "XPath"
first. Later MSXML version (e.g. 4/5/6) do support XPath by default.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| |
| Dave F. 2007-10-01, 6:16 pm |
| Martin Honnen wrote:
> Dave F. wrote:
>
>
> Yes, but with MSXML 3 you need to set
> MsDom.setProperty "SelectionLanguage", "XPath"
> first. Later MSXML version (e.g. 4/5/6) do support XPath by default.
>
>
Thanks to both for your replies.
I'm using v4, so it must be a problem with the syntax. Which is what's
confusing me.
It returning just the first node it finds. I thought it returned a node
with all the test strings beginning with 5.
You'll have to excuse me, I'm newish to XML/XPATH. & not sure what I'm
doing.
Can you point me in the right direction?
Cheers
Dave F.
| |
| Joe Fawcett 2007-10-01, 6:16 pm |
| If it works with SelectNodes then it's the same with SelectSingleNode, which
just delegates to SelectNodes and returns the first in the list.
The Offset you specified was 2, not 5, the XPath should look like:
/Offset/Dist/x[starts-with(., '2')]
so make sure that's what you get my using a MsgBox or similar to display the
final XPath before using it.
--
Joe Fawcett (MVP - XML)
http://joe.fawcett.name
"Dave F." <df@bh.cu.uk> wrote in message
news:%23weak2EBIHA.4836@TK2MSFTNGP06.phx.gbl...
> Martin Honnen wrote:
>
> Thanks to both for your replies.
> I'm using v4, so it must be a problem with the syntax. Which is what's
> confusing me.
> It returning just the first node it finds. I thought it returned a node
> with all the test strings beginning with 5.
>
> You'll have to excuse me, I'm newish to XML/XPATH. & not sure what I'm
> doing.
>
> Can you point me in the right direction?
>
> Cheers
> Dave F.
| |
| Brian Staff 2007-10-01, 6:16 pm |
| > You'll have to excuse me, I'm newish to XML/XPATH. & not sure what I'm
> doing.
http://support.microsoft.com/kb/303516
suggestion...recode this:
Set NodeLst = MsDom.selectNodes("/Offset/Dist/x[starts-with(.,'" &
OffsetNo & "')]")
to this:
dim xpath
xpath = "/Offset/Dist/x[starts-with(.,'" &
OffsetNo & "')]"
' now you can see what xpath has evaluated to...
Set NodeLst = MsDom.selectNodes(xpath)
Another thing...is the node Offset your root node?
If so, you do not need the first slash.
xpath = "Offset/Dist/x[starts-with(.,'" &
OffsetNo & "')]"
Brian
|
|
|
|
| Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |