473,387 Members | 1,512 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,387 software developers and data experts.

xerces serializing <

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).
cheers

shaun
Nov 2 '05 #1
3 2532
shaun roe (sh*******@wanadoo.fr) 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>

: 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.
Nov 2 '05 #2


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/
Nov 3 '05 #3
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

Nov 6 '05 #4

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

Similar topics

3
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
12
by: Sammy | last post by:
Hi, my mind is going crazy. I have tried everything I can think of to no avail. I have tried Disable Output Escaping. I tried to think of a way of enclosing the attribute data in a CDATA...
4
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I...
2
by: Francesco Moi | last post by:
Hello. I designed a form to edit some DataBase's fields. But some of these fields contain '&lt;' and '&gt;' characters. And these characters are '<' and '>' in HTML. So if want to edit these...
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
3
by: webmasterATflymagnetic.com | last post by:
Folks, I'm struggling to put the question together, but I have this problem. I have written an HTML form that I can use for data entry. This uses PHP to write a SQL UPDATE command that gets...
4
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report>...
1
by: ismailc | last post by:
Hi, I need help please. Update system to to new version & moved on to .Net2 But now my code that worked in my .Net1 xslt does not work. .Net1 fine: <xsl:stylesheet...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.