| Author |
MSXML Text property
|
|
| John Lewe \(QuoteWerks\) 2007-04-18, 6:16 pm |
| Hi All,
I have the following XML in a variable:
<?xml version="1.0" encoding="UTF-8"?><TopLevelWrapperTag>
<EnablePDSLevelSecurity>1</EnablePDSLevelSecurity>
<StockOptions>2<Buy>1</Buy></StockOptions>
</TopLevelWrapperTag>
I use the following code with MSXML ;
Dim oNode As MSXML.IXMLDOMNode
Set oNode = oXML.selectSingleNode("TopLevelWrapperTag/StockOptions")
Msgbox oNode.Text
oNode.Text returns "21"
I am expecting it to just return "2" or even "2<Buy>1</Buy>"
Any ideas why it returns what it does? And more importantly, does anyone
know how the code needs to be adjusted to be able to request the value of
the "StockOptions" node which should be '2"/
Thanks in advance.
John
| |
| Martin Honnen 2007-04-18, 6:16 pm |
| John Lewe (QuoteWerks) wrote:
> <StockOptions>2<Buy>1</Buy></StockOptions>
> </TopLevelWrapperTag>
>
>
> I use the following code with MSXML ;
>
> Dim oNode As MSXML.IXMLDOMNode
> Set oNode = oXML.selectSingleNode("TopLevelWrapperTag/StockOptions")
>
> Msgbox oNode.Text
>
> oNode.Text returns "21"
>
> I am expecting it to just return "2" or even "2<Buy>1</Buy>"
The text property concatenates the text contents of all child and
descendant text nodes of the element. That StockOptions element has two
child nodes, one text node with contents "2" and the Buy element which
has a text child with contents "1" so the StockOptions elements has two
text node descendants and "2" concatenated with "1" gives "21".
If you want the first text node child of the StockOptions element use
the XPath TopLevelWrapperTag/StockOptions/text() with selectSingleNode.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| |
| John Lewe 2007-04-19, 6:20 pm |
| Thanks for the quick response!
Is there a way to still use;
Set oNode = oXML.selectSingleNode("TopLevelWrapperTag/StockOptions")
but then return the text property from the the oNode somehow?
I ask because my code looks at various nodes and it is cleaner for me if i
can reference it from the node...
John
-original message----
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:uFyK82dgHHA.588@TK2MSFTNGP06.phx.gbl...
> John Lewe (QuoteWerks) wrote:
>
>
> The text property concatenates the text contents of all child and
> descendant text nodes of the element. That StockOptions element has two
> child nodes, one text node with contents "2" and the Buy element which has
> a text child with contents "1" so the StockOptions elements has two text
> node descendants and "2" concatenated with "1" gives "21".
>
> If you want the first text node child of the StockOptions element use the
> XPath TopLevelWrapperTag/StockOptions/text() with selectSingleNode.
>
>
>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
| |
| Martin Honnen 2007-04-19, 6:20 pm |
| John Lewe wrote:
> Is there a way to still use;
>
> Set oNode = oXML.selectSingleNode("TopLevelWrapperTag/StockOptions")
>
> but then return the text property from the the oNode somehow?
>
> I ask because my code looks at various nodes and it is cleaner for me if i
> can reference it from the node...
The text property does not give you what you want in that case (of
poorly structured markup). What you can do is break up the XPath
expression e.g.
Set oElement = oXML.selectSingleNode("TopLevelWrapperTag/StockOptions")
Set oTextNode = oElement.selectSingleNode("text()")
' access oTextNode.text or oTextNode.data here
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
|
|
|
|
| Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |