473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Deserialize XML where XML may contain XML

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

Jul 5 '06 #1
1 2071
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
Jul 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Carl Mercier | last post by:
Hi! I have 2 different applications/assembly. The first one creates an object and serializes it to a textfile on disk. The second one has the the exact same class (copied/pasted). It reads...
0
by: John Manion via .NET 247 | last post by:
Long Post, thanks for your patience... I have and XML file that looks something like this: <?xml version="1.0" encoding="utf-8" ?> <Settings> <Location> <X>30</X> <Y>40</Y> </Location>...
2
by: Hal Heinrich | last post by:
I'm saving an object to isolated storage to preserve user session information. Over time I add new variables to the session object. This breaks the deserialization of the object with an...
3
by: Parag Mahajan | last post by:
Hello, I would like to know if one can overload System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader) method? Thanks, Parag.
2
by: Ahmad Jalil Qarshi | last post by:
Hi! I have two applications A and B. I used the BinaryFormatter object to serialize and deserialize object of Structure "st" in my Applicaion "A". Now I tried to Deserialize that Object...
0
by: PSingh | last post by:
Hi, I know this is a frequently asked question but have tried several combinations and cant seem to figure this out. I am serializing my object as follows: XmlSerializer serializer = new...
6
by: Peter Franks | last post by:
Is it possible to deserialize a class that has a public property w/ a setter, but no getter? I'm not finding anything that would allow this -- Presuming that is is NOT possible, what are the...
1
by: Julien Sobrier | last post by:
Hello, I'm trying to deserialize an RSS feed that can contains 2 namespaces. FOr example, it can contain a tag <imageand/or <itunes:images>. I couldn't figure out how to get both. This simplified...
2
by: jonker | last post by:
Hi All, I have a TCP Client which reads the data from the socket. Now I have to deserialize the received data. The data can contain multiple XML documents like : <customer field="value"> ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.