CDATA Question

M

mike

Hi People,

Wondering whether anyone can help me with a beginner question. I would like
to embed some xml within xml. I've tried wrapping it with CDATA but no
success. What I would like to achieve is something like this:

<xml>
<msg type='methodCall'>
<method name='Stop'>
<params Id='200701081215'
Dest='Some text here'
Source='<xml><Person name='Mike'></Person></xml>'
/>
</method>
</msg>
</xml>

Is such a thing possible?

Mike
 
M

Magnus Henriksson

mike said:
Hi People,

Wondering whether anyone can help me with a beginner question. I would like
to embed some xml within xml. I've tried wrapping it with CDATA but no
success. What I would like to achieve is something like this:

<xml>
<msg type='methodCall'>
<method name='Stop'>
<params Id='200701081215'
Dest='Some text here'
Source='<xml><Person name='Mike'></Person></xml>'
/>
</method>
</msg>
</xml>


You cannot have elements named 'xml'.

Other than that, would something like this work?:

<yml>
<msg type='methodCall'>
<method name='Stop'>
<params Id='200701081215' Dest='Some text here'>
<Source>
<yml><Person name='Mike'></Person></yml>
<Source>
</method>
</msg>
</yml>


// Magnus
 
G

George Bina

Hi Mike,

CDATA sections cannot be placed inside an attribute value. You can have
something like below, escaping < and > with &lt; and &gt;. Note that
the Source attribute contains a string, you need to parse that to get
XML:

<xml>
<msg type="methodCall">
<method name="Stop">
<params Id="200701081215" Dest="Some text here"
Source="&lt;xml&gt;&lt;Person
name=&apos;Mike&apos;&gt;&lt;/Person&gt;&lt;/xml&gt;"
/>
</method>
</msg>
</xml>

Another thing is that the names starting with xml are reserved, you can
use them but it is recommended not to use them.

Best Regards,
George
 
P

Peter Flynn

mike said:
Hi People,

Wondering whether anyone can help me with a beginner question. I would like
to embed some xml within xml. I've tried wrapping it with CDATA but no
success. What I would like to achieve is something like this:

<xml>
<msg type='methodCall'>
<method name='Stop'>
<params Id='200701081215'
Dest='Some text here'
Source='<xml><Person name='Mike'></Person></xml>'
/>
</method>
</msg>
</xml>

Is such a thing possible?

If you could perhaps explain *why* you want to do this, it would help us
find a solution.

///Peter
 
M

mike

Hi Peter,

Thanks for taking the trouble. I believe I will do as George suggests. My
data was not very illustrative in my sample so I can understand your
question. For the sake of completeness, the "WHY" is as follows:

I'm transmitting a string of XML over a socket to a server. I want the
server to parse the XML and store bits of it in a database. But part of what
I want to transmit and store is another complete piece of XML. So, I want to
transmit an XML string, parse it to extract xml from one of its elements and
store THAT XML in a database.

The simple replacement of the "<" and ">" will do for now.

Thanks for taking the trouble,

MIKE
 

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,007
Messages
2,570,266
Members
46,865
Latest member
AveryHamme

Latest Threads

Top