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

Extracting values from CDATA

I am trying to get the values in FIELD2 and FIELD3 in the XML file
below using XSLT. I can get the value of CLOB_DATA. It comes back as
an string. How can I extract the values FIELD2 and FIELD3?

Thanks in advance.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<XML>
<FIELD1>field1</FIELD1>
<CLOB_DATA>
<![CDATA[<?xml version="1.0"?>
<FIELD2>field2</FIELD2>
<FIELD3>field3</FIELD3>
]]>
</CLOB_DATA>
</XML>

Jul 27 '06 #1
10 2449


Dana B wrote:
I am trying to get the values in FIELD2 and FIELD3 in the XML file
below using XSLT. I can get the value of CLOB_DATA. It comes back as
an string. How can I extract the values FIELD2 and FIELD3?
<CLOB_DATA>
<![CDATA[<?xml version="1.0"?>
<FIELD2>field2</FIELD2>
<FIELD3>field3</FIELD3>
]]>
</CLOB_DATA>
For that stuff in the CDATA section your XSLT stylesheet sees only a
string and no fields or elements. So you need to have a way to parse
that string as XML which needs an extension function, XSLT 1.0 can't do
that directly.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 27 '06 #2
Can you show me an example of how I can parse the XML string with an
extension function?

Thanks
Dana

Jul 27 '06 #3


Dana B wrote:
Can you show me an example of how I can parse the XML string with an
extension function?
That depends highly on which XSLT processor you use and whether it
supports that kind of extension function.
I could show you can example for MSXML with the extension function being
written in JScript but that does not help you at all if you are using a
diffetrent XSLT processor.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 27 '06 #4
Dana B wrote:
I am trying to get the values in FIELD2 and FIELD3 in the XML file
below using XSLT.
That's not XML - That's XML, wrapped up as a string, wrapped up in more
XML. Three layers of data! It's not only hard to parse, it actually
_means_ something quite different. Of course it might be intended to
mean the same thing after all, so don't take that difference too
seriously.

Now XSLT likes to see XML and it will (grudgingly) let you work with
strings inside XML. However it has no way to work with XML inside this
(3rd layer down).

If you want to work with this then you need to tree walk the outer XML
to get the strings, then pass this content to an XML parser! It's not
hard to do in a script language with a DOM (Java / JavaScript / Perl /
VB), although I'm not keen on the efficiency aspects.

As to doing it _within_ XSLT then I've never tried it, but it ought to
work fairly much the same, so long as you have an extension language
like JavaScript with access to a suitable DOM.

The real solution though is to not wrap it up in the first place. Is
this "inner" XML really well-formed XML ? Is it a well-formed fragment,
or is it also a well-formed XML document? (your's isn't - two root
elements) If it isn't, then any attempt to parse it is doomed. If it
is (even if it's a fragment) then why was it put in a CDATA section to
begin with ?

If this "inner" content _is_ XML, then there's no reason at all to wrap
it in a CDATA section. This is what namespacing is for, after all.

Jul 27 '06 #5
Why are you using the CDATA section in the first place? If the data's
structure is important, make that part of the structure of your
document, not a string value.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jul 27 '06 #6
I didn't create the XML but I have to parse it. I'm not sure why they
used CDATA. There are probably characters that they didn't want to
encode. I am trying to parse the fields and convert it to CSV using
XSLT if possible and practical. If not, I will use Java.

Jul 28 '06 #7
If you're really stuck with it... I agree with others who said the
cleanest solution is to extract the contents of the CDATA section and
run them through a second parsing pass.

Your customer handed you lemons. Make lemonade.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Jul 28 '06 #8


*** Sent via Developersdex http://www.developersdex.com ***
Sep 4 '06 #9


I have the same problem, i have an xml document that i can't change its
CDATA section which contain data in xml format that i need to browse in
html format using xslt1.0 .

the result in the parser is text written in xml format.

I need your help,

Thanks in advance,

Naim KANJ

*** Sent via Developersdex http://www.developersdex.com ***
Sep 4 '06 #10
Naim KANJ wrote:
>
I have the same problem, i have an xml document that i can't change its
CDATA section which contain data in xml format that i need to browse in
html format using xslt1.0 .

the result in the parser is text written in xml format.
Tell the originators to remove the CDATA markup before they send you
the document.

Or filter it out in a script to another file before you process it.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Sep 4 '06 #11

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

Similar topics

5
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
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,...
2
by: Damon | last post by:
I'm getting errors using XML deserialisation and CDATA sections when there are hexidecimal characters involved. If the CDATA section does not contain a hexidecimal values everything is fine....
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);...
4
by: james.eaton | last post by:
I have an XML Schema Document (.xsd) that contains documentation tags (specifically, custom tags subordinate xsd:appinfo). These documentation tags contain strings that may contain ampersands. I...
12
by: Peter Michaux | last post by:
Hi, I am experimenting with some of the Ruby on Rails JavaScript generators and see something I haven't before. Maybe it is worthwhile? In the page below the script is enclosed in //<!]> ...
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: Edsel | last post by:
Hi all, Can anyone help with this? I would like to extract the attributes from a XML node and then transform them back to XML as elements using XSLT? <unsorted> <office...
1
by: paragguptaiiita | last post by:
i have one problem in my XML file i have CData like this <college name="JDSVM" id="121" > <!]> <Comment> <!]> </college> in my XSL file, for taking the value of name...
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:
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.