xerces serializing <

Discussion in 'XML' started by Malcolm Dew-Jones, Nov 2, 2005.

  1. shaun roe () wrote:
    : a follow up with new problems from my previous post:

    : I have xml encoded in a string with elements like <myElement/>

    : e.g

    : <codeFragment> &lt;myElement&gt;some text&lt;/myElement&gt;
    : </codeFragment>

    : I parse this in Xerces and I can see it has done the correct thing,
    : but now I want to serialize the output so it **looks** like valid xml,
    : i.e.
    : <codeFragment> <myElement>someText</myElement> </codeFragment>

    : this doesnt happen; instead I get

    : <codeFragment> &lt;myElement>someText &lt/myElement> </codeFragment>

    : I dont want to change the DOM model, I just want the serializer to
    : output text which has the "<" in it. Is there some way of stopping it
    : escaping the "<" ?

    : note: unfortunately I am restricted to simple text in the node, I cannot
    : insert a CDATA. (not sure this would solve it anyway).


    Is there some option to _not_ escape the text? I know that using xalan
    you can use an option (it's part of xlst) to not escape text. Since xalan
    is based on xerces, I wonder if it is xerces that has an option to do
    this?

    OR

    Take your text after it is un-escaped and parse that a second time. Now
    take that small node tree and splice it into the original in place of the
    text that contained the escaped < & >'s. When the whole is serialized
    then that part of the xml will be output with tags as you wish. ($0.10)

    --

    This programmer available for rent.
     
    Malcolm Dew-Jones, Nov 2, 2005
    #1
    1. Advertising

  2. Malcolm Dew-Jones

    shaun roe Guest

    a follow up with new problems from my previous post:

    I have xml encoded in a string with elements like &lt;myElement/&gt;

    e.g

    <codeFragment> &lt;myElement&gt;some text&lt;/myElement&gt;
    </codeFragment>

    I parse this in Xerces and I can see it has done the correct thing,
    but now I want to serialize the output so it **looks** like valid xml,
    i.e.
    <codeFragment> <myElement>someText</myElement> </codeFragment>

    this doesnt happen; instead I get

    <codeFragment> &lt;myElement>someText &lt/myElement> </codeFragment>

    I dont want to change the DOM model, I just want the serializer to
    output text which has the "<" in it. Is there some way of stopping it
    escaping the "<" ?

    note: unfortunately I am restricted to simple text in the node, I cannot
    insert a CDATA. (not sure this would solve it anyway).


    cheers

    shaun
     
    shaun roe, Nov 2, 2005
    #2
    1. Advertising

  3. shaun roe wrote:

    > I have xml encoded in a string with elements like &lt;myElement/&gt;
    >
    > e.g
    >
    > <codeFragment> &lt;myElement&gt;some text&lt;/myElement&gt;
    > </codeFragment>
    >
    > I parse this in Xerces and I can see it has done the correct thing,
    > but now I want to serialize the output so it **looks** like valid xml,
    > i.e.
    > <codeFragment> <myElement>someText</myElement> </codeFragment>


    You can only talk about "valid" XML if you have a DTD or schema.
    As for those snippets, both are "well-formed" XML, obviously the first
    one is one elements with some text as a child node while the second is
    an element with text and an element as child nodes.


    > this doesnt happen; instead I get
    >
    > <codeFragment> &lt;myElement>someText &lt/myElement> </codeFragment>


    Text has to be serialized with '<' escaped as &lt;, otherwise it is not
    a proper serialization.

    > I dont want to change the DOM model, I just want the serializer to
    > output text which has the "<" in it. Is there some way of stopping it
    > escaping the "<" ?


    If you first choose to escape some XML markup as text in an XML document
    you can't complain that the XML tools then treat that as text. Of course
    with the DOM you can read out the text contents of an element and then
    feed that to a new DOM parser to parse it as XML.
    Or you would need to write your own serializer traversing a DOM tree and
    not escaping text contents or perhaps not escaping text contents in
    certain elements.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Nov 3, 2005
    #3
  4. Malcolm Dew-Jones

    Peter Flynn Guest

    shaun roe wrote:

    > a follow up with new problems from my previous post:
    >
    > I have xml encoded in a string with elements like &lt;myElement/&gt;
    >
    > e.g
    >
    > <codeFragment> &lt;myElement&gt;some text&lt;/myElement&gt;
    > </codeFragment>


    That isn't XML. It's text that happens to have character entities in it.

    > I parse this in Xerces and I can see it has done the correct thing,
    > but now I want to serialize the output so it **looks** like valid xml,
    > i.e.
    > <codeFragment> <myElement>someText</myElement> </codeFragment>
    >
    > this doesnt happen; instead I get
    >
    > <codeFragment> &lt;myElement>someText &lt/myElement> </codeFragment>
    >
    > I dont want to change the DOM model, I just want the serializer to
    > output text which has the "<" in it. Is there some way of stopping it
    > escaping the "<" ?
    >
    > note: unfortunately I am restricted to simple text in the node, I
    > cannot insert a CDATA. (not sure this would solve it anyway).


    See the FAQ: http://xml.silmaril.ie/authors/html/

    ///Peter
     
    Peter Flynn, Nov 6, 2005
    #4
    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. Aidan Glendye

    Serializing classes derived from dataset

    Aidan Glendye, Jul 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    516
    Aidan Glendye
    Jul 28, 2003
  2. Jason Shohet
    Replies:
    4
    Views:
    368
    bruce barker
    Jul 29, 2003
  3. MattB

    problem de-serializing a dataset

    MattB, Apr 27, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    379
    MattB
    Apr 27, 2004
  4. Russ
    Replies:
    1
    Views:
    359
    Peter Morris
    Aug 10, 2004
  5. cvissy
    Replies:
    0
    Views:
    637
    cvissy
    Nov 16, 2004
Loading...

Share This Page