473,890 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath and CDATA

Hi,

Is it possible to retrieve CDATA Sections from an XML document? If so,
could someone give me a syntax example?

Cheers

Aidy

Mar 17 '06
15 18517
Below is the XSL I have got. I am trying to assign the value of the
MESSAGE_TEXT node to a variable, then do a contains to gather whether
that text has a substring of 'TESTID'. Then I wanna write that value to
the HTML. However when I run the transformation, I receive this error:
'A string literal was expected, but no opening quote character was
found. <xsl:if test=contains(" $host1","TESTID ")', so at the moment I
am a bit stuck.

<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<HTML>
<xsl:for-each select="SAFS_LO G/LOG_MESSAGE">
<P>
<!-- <xsl:value-of select="MESSAGE _TEXT"/> -->

<xsl:variable name="host1" select="MESSAGE _TEXT"/>
<xsl:if test=contains(" $host1","TESTID ")
<xsl:value-of select="$host1"/>
</P>
</xsl:if>
</xsl:for-each>
</HTML>
</xsl:template>
</xsl:stylesheet>

Cheers

Aidy

Mar 25 '06 #11
That sounds like you're trying to style HTML. HTML is not XML -- it's
SGML -- and permits some things that XML doesn't, such as attribute
values without quotes around them.

If that's what you're trying to do, you need to get a parser that can
read HTML (I believe the W3C's "tidy" tool can be persuaded to do this
for you, or try the NekoHTML parser based on the Apache Xerces system)
and do a bit of simple API programming to use that to feed the document
to the stylesheet.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 25 '06 #12
aidy wrote:
Below is the XSL I have got. I am trying to assign the value of the
MESSAGE_TEXT node to a variable, then do a contains to gather whether
that text has a substring of 'TESTID'. Then I wanna write that value to
the HTML. However when I run the transformation, I receive this error:
'A string literal was expected, but no opening quote character was
found. <xsl:if test=contains(" $host1","TESTID ")', so at the moment I
am a bit stuck.


I think you need to remove the quotes around "$host1".

///Peter
Mar 26 '06 #13
Hi,

This is a snippet of the XML

<SAFS_LOG>
<LOG_MESSAGE type="GENERIC" date="27-03-2006" time="10:56:06" >
<MESSAGE_TEXT>< ![CDATA[.TESTID_10]]></MESSAGE_TEXT>
</LOG_MESSAGE>
<LOG_MESSAGE type="FAILED" date="27-03-2006" time="10:56:08" >
<MESSAGE_TEXT>< ![CDATA[Country Code: GB <> AU </MESSAGE_TEXT>
</LOG_MESSAGE>
<LOG_MESSAGE type="GENERIC" date="27-03-2006" time="10:56:10" >
<MESSAGE_TEXT>< ![CDATA[.TESTID_20]]></MESSAGE_TEXT>
</LOG_MESSAGE>
<LOG_MESSAGE type="PASSED" date="27-03-2006" time="10:56:13" >
<MESSAGE_TEXT>< ![CDATA[AddressServiceW in DOES EXIST as
expected.]]></MESSAGE_TEXT>
</LOG_MESSAGE>

</SAFS_LOG>

I have managed to extract the TESTID's from the MESSAGE_TEXT by using
this xsl

<xsl:template match="/">
<HTML>
<head><title>Ad dress Service Test Log </title></head>

<body>
<h2>Test Summary</h2>
<tr><th><B> TEST ID</B></th></tr>
<xsl:for-each select="SAFS_LO G/LOG_MESSAGE">
<xsl:variable name="host1" select="MESSAGE _TEXT"/>
<xsl:if test="(contains ($host1,'.TESTI D'))">
<table border="1">
<td> <xsl:value-of select="$host1"/> </td>
</table>
</xsl:if>
</xsl:for-each>
</body>
</HTML>
</xsl:template>
</xsl:stylesheet>

In the HTML I get something like this

Test Summary
TEST ID

..TESTID_10
..TESTID_20

Now I want to extract from the xml whether these tests have passed or
failed - as we can see above we have got a 'FAILED' on the TESTID_10
and a 'PASSED' on TESTID_20

The code I have added is enclosed in asterisks

<xsl:for-each select="SAFS_LO G/LOG_MESSAGE">
<xsl:variable name="host1" select="MESSAGE _TEXT"/>
<xsl:if test="(contains ($host1,'.TESTI D'))">
<table border="1">
<td> <xsl:value-of select="$host1"/> </td>

*************** *************** *************** *************** **
<xsl:variable name="host2" select="@type"/>
<xsl:if test="(contains ($host2,'FAILED '))">
<td> <xsl:value-of select="MESSAGE _TEXT"/> </td>
</xsl:if>
*************** *************** *************** *************** **

</table>
</xsl:if>
</xsl:for-each>

I don't seem to be returning any 'FAILED' even though they are in
<LOG_MESSAGE> . Does anyone know why?

Cheers

Aidy

Mar 27 '06 #14
I need to extract a data from CDATA section of XML.That is not an issue
for me as what CDATA secion contains.I just need that section only as a
string or file or whatever. Pls help.


*** Sent via Developersdex http://www.developersdex.com ***
Mar 31 '06 #15
In article <er************ **@news.uswest. net>,
Rajesh Kochhar <ra************ @abnamro.com> wrote:
I need to extract a data from CDATA section of XML.That is not an issue
for me as what CDATA secion contains.I just need that section only as a
string or file or whatever. Pls help.


You can't extract a CDATA section with XPath. You will have to specify
the characters you want by some other means, such as the element they
are contained in.

-- Richard
Mar 31 '06 #16

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

Similar topics

2
5184
by: Nold Fuchs | last post by:
Hi ! I need to isolate some nodes without CDATA inside, the problem is that I can not get an XPATH to differentiate simple text nodes and CDATA nodes. Sample XML : <nodes> <node>some text</node> <node><!]></node> </nodes>
1
406
by: Chris Fink | last post by:
What is a valid XPath Statement to retrieve the data found within the CDATA tag below? Using the XPath statement "/oid" returns "" <oid><!]></oid>
3
1785
by: Sébastien Ros | last post by:
I tries to migrate an existing application from 1.1 to 2.0 but it seems that one of my XPath expressions no more works on this version. I tried a SelectNodes().Count. The result is 1 in v1.1 and 0 in v2.0. Here is the XPath expression: //Entity = 'Undefined')] And the corresponding XML file fragment (the file contains the DTD):
2
1307
by: vjethava | last post by:
Hi, I'm relatively new to xml. I want to have a xml element of the form: <!ELEMENT CAR (MAKE, COMPANY)> <!ATTLIST CAR TYPE PCDATA PRICE PCADATA> <!ELEMENT COMPANY (HQ, COMPANY_TYPE)>
11
6480
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); XPathNavigator nav = docNav.CreateNavigator(); XmlDocument doc = new XmlDocument(); doc.LoadXml("<DocumentData></DocumentData>"); XmlElement elem = doc.CreateElement(currentNodeName);
5
2011
by: dotnetnoob | last post by:
i got xml file that have <bac:BACnetDevicesand <bac:BACnetDevicetag how do you make a xpath query with that type of tags this is the query that i come up with /Site/Networks/Network/bac:BACnetDevices/bac:BACnetDevice/@InstanceNumber but i got "undefined namespace prefix -'bac'" error
3
2217
by: werD | last post by:
Hello I have an xml document that im currently using a forward only .net repeater on and using some xpath queries to display the data The xml is quite simple <?xml version="1.0" encoding="utf-8" ?> <data> <supervisors>
2
17566
by: Pugi! | last post by:
Using AJAX I want to send some information from the server (php-page) as XML to the client. The contents can be very divers so I have to use XML instead of text. On one occasion the contents is html, I can put this in a CDATA section with PHP, but how do I retrieve that information with Javascript and put the HTML in a div ? thanx, Pugi!
6
4832
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 city values should display in city selection field and when user select any one city value then this state of this city should be display auto in state selection field without user selection. please solve my prolem. Thank you.
0
9980
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9826
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11236
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10830
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10925
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7172
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5855
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3283
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.