perfectxml.com
 Basic Search  Advanced Search   
Topics Resources Free Library Software XML News About Us
home » focus » msxml » ask a question » past questions & answers Friday, 12 October 2007
 
NEWS
MSXML 4.0 SP2 now available!

 
MSXML
Basics
DOM
SAX
XPath
XSLT
Schemas
SOM
HTTP Access
.NET
Data Islands
Ask a Question
   Past Q&As
C++ Samples
DLL/Version Info
Reference Guide
Books
KB Articles
   HOW TO
   SAMPLE
   INFO
   BUG/PRB
   FIX
   Misc.
MSXML Tips
   August 2002
   September 2002
MSXML Tools

Microsoft XML Core Services


Go back to list of previously asked questions and answers

Question: I am using MSXML 3.0 in Visual Basic to load the XML document and select a node based on XPath expression. However, as the attribute value contains a single quote, I am stuck as to how the XPath expression should look like. Can you please help?

Consider the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<test>
	<users  FirstName="Roberts" LastName="Tim" UserName="tim'roberts" Password="123" />
	<users  FirstName="Gerry" LastName="Richard" UserName="timroberts" Password="123" /> 
</test>
Asked By: Sathya
Viewed: 1477
Answer: Try the following Visual Basic Example (add reference to MSXML 3.0):
Dim ObjXML As New MSXML2.DOMDocument30
Dim ANode As IXMLDOMNode
ObjXML.async = False

If ObjXML.Load("c:\1.xml") Then
    Set ANode = ObjXML.selectSingleNode("//users[@UserName=""tim'roberts""]")
    If Not ANode Is Nothing Then
        MsgBox ANode.Attributes(0).nodeTypedValue
    Else
        MsgBox "Not found!"
    End If
Else
    MsgBox "Error: " & ObjXML.parseError.reason
End If


Go back to list of previously asked questions and answers
  Contact Us | E-mail Us | Site Guide | About PerfectXML | Advertise ©2004 perfectxml.com. All rights reserved. | Privacy