nick_nw wrote:
Hi,
Given the following XML (cut down version for explanation, actual doc
much larger).
<?xml version="1.0" encoding="utf-8" ?>
<Stuff>Any string can go in here. It could even be well or badly
formed XML.</Stuff>
When I try to deserialize this document (all I want is the string
content of <StuffI get an error if <Stuffcontains XML.
How can instruct the XmlSerializer to ignore the contents of the
<Stuffelement? The only thing I can guarantee is that <Stuffwill
never contain a "</Stuff>" or "<Stuff>" string, but it might contain a
"/>" string.
Am I trying to do the impossible?
Is there a better way to achieve what I want to achieve?
Thanks in advance,
Nick
Hi Nick,
Am I trying to do the impossible?
Quite possibly... because even though in a flash, you or I can tell when XML
data appears inside an element (based on our personal perceptions, due to
identation, structure, spelling, context, etc) an XML parser is not that
clever. If the parser reads an element, it doesn't know that it's now
about to read some rubbish, including XML characters like the chevrons,
followed by an end-element.
I believe the answer lies in slightly altering the format of your XML file:
<?xml version="1.0" encoding="utf-8" ?>
<Stuff><![CDATA[Now put your <XMLstuff that may be <BADLYformed
here]]></Stuff>
The data that may contain malformed XML is wrapped in a
<![CDATA[...]]>
block, where ... is your data.
The following URL may help you:
http://www.w3schools.com/xml/xml_cdata.asp
--
Hope this helps,
Tom Spink