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

Wrapping XML in CDATA

Hi all,
I have two XML DOMs and I am trying to insert one into another, so that

<?xml = ....>
<Body>
<Head>
</Head>
</Body>

and

<?xml = ....>
<Eyes>
</Eyes>

Now becomes

<?xml = ....>
<Body>
<Head>
<Eyes>
</Eyes>
</Head>
</Body>

I have this working, with no problem...but what I would like to do is
produce the
following output instead:

<?xml = ....>
<Body>
<Head>
<![CDATA[
<Eyes>
</Eyes>
]]>
</Head>
</Body>

Is there anyway to do this? It seems to be tricky to do, as you can't
precede the
root xml declaration in the 2nd XML structure, (and anyway, it gets cut
out during
the splice)

Best wishes

Paul

--
http://www.paullee.com

Jul 20 '05 #1
5 7421
In article <40******@baen1673807.greenlnk.net>,
But I Haven't Eaten Any Sweetcorn! <pa********@aesystems.com> wrote:

[...using DOM, currently combine two documents to become one:]

% <?xml = ....>
% <Body>
% <Head>
% <Eyes>
% </Eyes>
% </Head>
% </Body>
%
% I have this working, with no problem...but what I would like to do is
% produce the
% following output instead:
%
% <?xml = ....>
% <Body>
% <Head>
% <![CDATA[
% <Eyes>
% </Eyes>
% ]]>
% </Head>
% </Body>

% Is there anyway to do this?

You need to convert the inserted document to a string, then add that
to the containing document as the text of a CDATA node in the
appropriate spot.

% Is there anyway to do this? It seems to be tricky to do, as you can't
% precede the
% root xml declaration in the 2nd XML structure, (and anyway, it gets cut
% out during
% the splice)

In a CDATA section, you can include anything you want, except for `]]>'.
If you don't want text that looks like an xml declaration, don't generate
one when you serialise the included document.

--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #2
Hi Patrick,
I think I understand. Do you mean finding the correct spot in the insert
DOM,
add a CDATA tag, and then insert the second DOM.

I'm currently experimenting by, rather than parsing in an input file in
Java, reading it in as a string (without the opening "<?xml..." declaration)
and trying to work
on this

of course, the following statement:
InputSource source = new InputSource(new StringReader( "&lt;![CDATA[" +
inserted_text + "}}&gt;" ));

inserted_text = builder.parse(source);

// inserting code goes here

....doesn't work....
- which would be ideal!

--

Cheers
Paul
------------------------------------------------
Paul's Squalid World at
http://www.paullee.com
"Patrick TJ McPhee" <pt**@interlog.com> wrote in message
news:c1**********@news.eusc.inter.net...
In article <40******@baen1673807.greenlnk.net>,
But I Haven't Eaten Any Sweetcorn! <pa********@aesystems.com> wrote:

[...using DOM, currently combine two documents to become one:]

% <?xml = ....>
% <Body>
% <Head>
% <Eyes>
% </Eyes>
% </Head>
% </Body>
%
% I have this working, with no problem...but what I would like to do is % produce the
% following output instead:
%
% <?xml = ....>
% <Body>
% <Head>
% <![CDATA[
% <Eyes>
% </Eyes>
% ]]>
% </Head>
% </Body>

% Is there anyway to do this?

You need to convert the inserted document to a string, then add that
to the containing document as the text of a CDATA node in the
appropriate spot.

% Is there anyway to do this? It seems to be tricky to do, as you can't % precede the
% root xml declaration in the 2nd XML structure, (and anyway, it gets cut % out during
% the splice)

In a CDATA section, you can include anything you want, except for `]]>'.
If you don't want text that looks like an xml declaration, don't generate one when you serialise the included document.

--

Patrick TJ McPhee
East York Canada
pt**@interlog.com


Jul 20 '05 #3
People have argued that doing this is a bad thing.
Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
"But I Haven't Eaten Any Sweetcorn!" <pa********@baesystems.com> wrote in
message news:40******@baen1673807.greenlnk.net...
Hi all,
I have two XML DOMs and I am trying to insert one into another, so that

<?xml = ....>
<Body>
<Head>
</Head>
</Body>

and

<?xml = ....>
<Eyes>
</Eyes>

Now becomes

<?xml = ....>
<Body>
<Head>
<Eyes>
</Eyes>
</Head>
</Body>

I have this working, with no problem...but what I would like to do is
produce the
following output instead:

<?xml = ....>
<Body>
<Head>
<![CDATA[
<Eyes>
</Eyes>
]]>
</Head>
</Body>

Is there anyway to do this? It seems to be tricky to do, as you can't
precede the
root xml declaration in the 2nd XML structure, (and anyway, it gets cut
out during
the splice)

Best wishes

Paul

--
http://www.paullee.com


Jul 20 '05 #4
Yes. Sadly I have no control over this, or doing it. It seems to be the
only
way to interface with legacy software!

--

Cheers
Paul
------------------------------------------------
Paul's Squalid World at
http://www.paullee.com
"Dimitre Novatchev [MVP XML]" <dn********@yahoo.com> wrote in message
news:c1*************@ID-152440.news.uni-berlin.de...
People have argued that doing this is a bad thing.
Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
"But I Haven't Eaten Any Sweetcorn!" <pa********@baesystems.com> wrote in message news:40******@baen1673807.greenlnk.net...
Hi all,
I have two XML DOMs and I am trying to insert one into another, so that
<?xml = ....>
<Body>
<Head>
</Head>
</Body>

and

<?xml = ....>
<Eyes>
</Eyes>

Now becomes

<?xml = ....>
<Body>
<Head>
<Eyes>
</Eyes>
</Head>
</Body>

I have this working, with no problem...but what I would like to do is produce the
following output instead:

<?xml = ....>
<Body>
<Head>
<![CDATA[
<Eyes>
</Eyes>
]]>
</Head>
</Body>

Is there anyway to do this? It seems to be tricky to do, as you can't precede the
root xml declaration in the 2nd XML structure, (and anyway, it gets cut out during
the splice)

Best wishes

Paul

--
http://www.paullee.com




Jul 20 '05 #5
In article <40********@baen1673807.greenlnk.net>,
But I Haven't Eaten Any Sweetcorn! <pa********@aesystems.com> wrote:

% I think I understand. Do you mean finding the correct spot in the insert
% DOM,
% add a CDATA tag, and then insert the second DOM.

No, I mean that you convert the second DOM to a string, create
the CDATA node such that its content is that string, then insert the
CDATA node at the appropriate spot.

% I'm currently experimenting by, rather than parsing in an input file in
% Java, reading it in as a string (without the opening "<?xml..." declaration)
% and trying to work
% on this

If you're starting with a file rather than a DOM tree, then this is the way
to go. You might need to be careful about ]]> in the input, though.

% InputSource source = new InputSource(new StringReader( "&lt;![CDATA[" +
% inserted_text + "}}&gt;" ));

I don't see this as ideal. Once you start using an API like DOM, you should
use it. If you want to do the string manipulation yourself, then don't
use DOM for any of it -- find the spot in the text of the first file and
insert the appropriate text from the second. And don't use &lt; when you
want <. If you're using DOM, though, you need to create a CDATA node with
the appropriate content and insert it into the tree.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #6

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

Similar topics

3
by: Balaras | last post by:
Hi, Can sombody here please help me a bit with a regular expression. I have a xml file where I need to strip the CDATA sections of any contained data. Eg. <xml> <tag><]></tag>...
6
by: Cade Perkins | last post by:
How can the CDATA ending delimiter "]]>" be represented within a CDATA section itself? Consider an XML document that is intended to contain an embedded, uninterpreted XML example. Generally,...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
4
by: Jake Barnes | last post by:
I'm reading over this page: http://wiki.script.aculo.us/scriptaculous/show/Usage I'm struck by this code example +++++++++++++++++++++++++++++++ 3. Use
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
1
by: soccerdad | last post by:
I've got a class hierarchy generated from a .xsd schema file using the XSD.EXE tool. One of the elements will have its "inner text" set to a CDATA block. The XSD.EXE tool exposed a "Value" property...
7
by: Max | last post by:
Hello everyone! Can anyone help me to convert the CDATA expression "CDATA ::= (Char* - (Char* ']]>' Char*)" to Javascript Regular Expression? Thanks, Max
1
by: s123 | last post by:
Hi, while invoking a web service, if in xml request message i wrap the extended ASCII characters with CDATA it is not returning the desired result, while this is not the case if i do not wrap...
6
by: dkyadav80 | last post by:
Hi sir, I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.