This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Solved -accessing Character Entity's via MSXML parser, in their original form...
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Solved -accessing Character Entity's via MSXML parser, in their original form...
- From: tcn at melvaig dot co dot uk (Trevor Nash)
- Date: Mon, 29 Oct 2001 08:30:13 GMT
- Cc: jdgarrett at alltel dot net
- Organization: Melvaig Software Engineering Limited
- References: <NBBBJCNHDKPCNLILCIOHOELLFIAA.jdgarrett@alltel.net>
- Reply-To: xsl-list at lists dot mulberrytech dot com
>Solved -accessing Character Entity's via MSXML parser, in their original
>form...
Now try as input
<?xml version="1.0"?>
<Company>
<AccountNumber Name="Ben & Jerry's"
PhoneNumber="555-1212">123456</AccountNumber>
</Company>
As David pointed out earlier, & is just another way of saying
& -- I will be very surprised if your output contains &.
If you ask for .Text then text is what you get - characters in their
raw form, i.e. & < etc.
If you ask for .xml then you will get something suitable for inclusion
in an XML document, i.e. with special characters escaped.
Maybe this is what you want, but don't confuse yourself (and others
who might come across your message in the archive) by saying
>
>and so I can now finally retrieve the node
>attribute value as it exists in the original XML structure ....
>
It's not that at all, it just looks like it when the input follows the
same escaping conventions as the output.
Regards,
Trevor Nash
>****************************************************************************
>*****
>
>Given the following XML structure ....
>
>***************************************************************************
><?xml version="1.0"?>
><Company>
> <AccountNumber Name="Ben & Jerry's"
>PhoneNumber="555-1212">123456</AccountNumber>
></Company>
>***************************************************************************
>
>where the above XML structure is set to a variable XML1
>
>
>and the following VB function...using the MSXML parser....
>
>***************************************************************************
>Function RetrieveValue() as String
>On Error GoTo errorhandler
>
> Dim XMLDoc As New MSXML2.DOMDocument30
> Dim selection As MSXML2.IXMLDOMSelection
> Dim strValue_1$, strValue_2$, strValue_3$, strValue_4$
> Dim bLoadError%
> Dim i%
>
> i = 0
> bLoadError = XMLDoc.loadXML(XML1)
> Set selection = XMLDoc.selectNodes("//AccountNumber")
>
> strValue_1$ = selection.Item(i).Attributes.getNamedItem("Name").Text
>
> strValue_2$ = selection.Item(i).Attributes.getNamedItem("Name").xml
>
> strValue_3$ =
>selection.Item(i).Attributes.getNamedItem("Name").firstChild.Text
>
> strValue_4$ =
>selection.Item(i).Attributes.getNamedItem("Name").firstChild.xml
>
>
> FindXMLCharacterEntity = strValue_4$
>
>Exit Function
>errorhandler:
>Resume Next
>End Function
>***************************************************************************
>
>..then the following values will be found
>
>strValue_1$ = Ben & Jerry's
>strValue_2$ = Name="Ben & Jerry's"
>strValue_3$ = Ben & Jerry's
>strValue_4$ = Ben & Jerry's
>
>and it is strValue_4$ that now finally allows me
>to return the value of the Name attribute
>as it exists in the XML structure before
>it is loaded ....by accessing firstChild.xml ....
>
>strValue_4$ =
>selection.Item(0).Attributes.getNamedItem("Name").firstChild.xml
>
>
>and so I can now finally retrieve the node
>attribute value as it exists in the original XML structure ....
>
>**********************************************************
>**********************************************************
>**********************************************************
>NOTE: "This is all I had wanted to begin with !!"
>**********************************************************
>**********************************************************
>**********************************************************
>
>or
>
>given
>.
>.
>.
><SomeNode SomeAttribute="ABC123" SomeOtherAttribute="Ben &
>Jerrys">123456</SomeNode>
>.
>.
>.
>
>
>Dim pbError as Boolean
>Dim XMLDOC As New MSXML2.DOMDocument30
>XMLDOC.setProperty "SelectionLanguage", "XPath"
>pbError = XMLDOC.Load(msXMLFile)
>
>XMLDOC.selectSingleNode("//SomeNode[@SomeAttribute =
>'ABC123' ]").Attributes.getNamedItem ("SomeOtherAttribute").firstChild.text
>
>will return Ben & Jerrys
>
>vs.
>
>XMLDOC.selectSingleNode("//SomeNode[@SomeAttribute =
>'ABC123' ]").Attributes.getNamedItem("SomeOtherAttribute").firstChild.xml
>
>but this will return Ben & Jerrys
>
>
>
Regards,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email
Melvaig Software Engineering Limited
voice: +44 (0) 1445 771 271
email: tcn@melvaig.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list