Encode XML

T

tlbollwitt

Hello,

I'm new to the world of XML.
I have a web service that returns a String of XML data.
I need to be able to encode that String so that when it gets validated
by the client it will be in a valid XML format.

Any example would be very appreciated.

Thanks.
Tom
 
O

Oliver Wong

Hello,

I'm new to the world of XML.
I have a web service that returns a String of XML data.
I need to be able to encode that String so that when it gets validated
by the client it will be in a valid XML format.

I can think of two interpretations of your problems.

(1) You want have an XML document which you want to pass to the client.
Solution: just pass it to the client. Presumably, it's already valid XML, or
else that web server you have is broken.

(2) Your client is expecting a XML encoded response which semantically
represents a string. It just so happens that coincidentally, this content is
XML data.
Solution: Escape the relevant characters.

For example, if you want to return the String which represents the following
XML document:

<XmlDocument>Hello World!</XmlDocument>

then escape the string as follows:

"&lt;XmlDocument&gt;Hello World!&lt;/XmlDocument&gt;"

and then put that string within your XML response:

<XmlResponse type="string">&lt;XmlDocument&gt;Hello
World!&lt;/XmlDocument&gt;</XmlResponse>

and then your problem reduces to (1) which was already solved.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top