Groups | Blog | Home
all groups > dotnet xml > october 2005 >

dotnet xml : Special Characters



MAF
10/5/2005 11:57:08 AM
Is there a quick way to convert all special characters to XML format for
example '&' to & or '+' sign to ? ?

Fraser Michael
10/5/2005 2:24:22 PM

It does in the XPATH I am getting the error on the following line:

XMLErrorCollection =
this.m_XMLDoc.SelectSingleNode("./PortfolioCollection/" +
this.m_PortfolioName + "/ErrorCollection");

Where m_PortfolioName = 'test + 1 day'


Martin Honnen
10/5/2005 9:16:23 PM


[quoted text, click to view]

'&' needs to be escaped as & but the '+' sign does not need to be
escaped in XML.

How you do it depends on the .NET APIs you use, if you use an
XmlTextWriter to create XML then the WriteString method for instance
does the escaping for you.

If you use the DOM then CreateTextNode simply takes your string and if
the DOM is serialized (e.g. InnerXml, OuterXml, Save) the escaping is
done automatically.



--

Martin Honnen --- MVP XML
Martin Honnen
10/6/2005 12:00:00 AM


[quoted text, click to view]

Well XPath does not have an XML syntax at all.

With the above you would get the XPath expression
./PortfolioCollection/test + 1 day/ErrorCollection
and that is not syntactically correct as an XPath expression so that is
why you get an error.
Escaping does not help to get the correct syntax.

--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button