CDATA Question

Discussion in 'XML' started by mike, Jan 23, 2007.

  1. mike

    mike Guest

    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
    mike, Jan 23, 2007
    #1
    1. Advertising

  2. mike <transam@ wrote:
    > 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
    Magnus Henriksson, Jan 23, 2007
    #2
    1. Advertising

  3. mike

    George Bina Guest

    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
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com

    mike wrote:
    > 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
    George Bina, Jan 23, 2007
    #3
  4. mike

    Peter Flynn Guest

    mike <transam@ wrote:
    > 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
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, Jan 23, 2007
    #4
  5. mike

    mike Guest

    Thanks George,

    I believe this is what I will do.

    Thanks to all who replied.

    MIKE



    "George Bina" <> wrote in message
    news:...
    > 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
    > ---------------------------------------------------------------------
    > George Cristian Bina
    > <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    > http://www.oxygenxml.com
    >
    > mike wrote:
    >> 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

    >
    mike, Jan 23, 2007
    #5
  6. mike

    mike Guest

    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



    "Peter Flynn" <> wrote in message
    news:...
    > mike <transam@ wrote:
    >> 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
    > --
    > XML FAQ: http://xml.silmaril.ie/
    mike, Jan 23, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Schmidt

    CDATA in XMLout

    Stefan Schmidt, Dec 28, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,267
    Andy R
    Dec 31, 2003
  2. John Davison
    Replies:
    1
    Views:
    565
    Hal Rosser
    Jul 7, 2004
  3. Razvan

    CDATA question

    Razvan, Jan 11, 2005, in forum: XML
    Replies:
    1
    Views:
    390
    David Carlisle
    Jan 11, 2005
  4. Replies:
    3
    Views:
    728
    Joe Kesselman
    Mar 6, 2006
  5. Dilip
    Replies:
    3
    Views:
    418
    Joseph Kesselman
    Oct 25, 2006
Loading...

Share This Page