How to get CDATA from xml node using xsl ?
By : Saurabh Srivastava
Date : March 29 2020, 07:55 AM
it fixes the issue Some other easy steps to achieve this; Used W3cschools editor to try out. code :
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<catalog>
<cd>
<disk id="title"><![CDATA[Sample xml]]></disk >
<disk id="artist"><![CDATA[Vijay]]></disk >
</cd>
</catalog>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="/catalog/cd/disk[@id='title']"/></td>
<td><xsl:value-of select="/catalog/cd/disk[@id='artist']"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
PHP XML editing CDATA node
By : user2097720
Date : March 29 2020, 07:55 AM
seems to work fine I have an XML file with some CDATA nodes. I want to change the text inside the CDATA node (keeping it as CDATA node). So, I guess I first need to read the CDATA node and then write it back. But, I am not sure how to do that in PHP. I was able to create a new CDATA node but how can I edit a CDATA node? Is there a direct way to do that? , I fixed it on my own: code :
$nodes = $xml->getElementsByTagName('tagname');
$oldTitleNode = null;
$newTitleNode = null;
//Iterate for each <title> tag
foreach ($nodes as $node) {
if ($node->parentNode->getAttribute('name')== $tag_name_value){
$oldTitleNode = $node;
//Create new CDATA Node
$newTitleNode=$node->parentNode->appendChild($xml->createElement('tagname'));
$cdata=$xml->createCDATASection($update_title);
$newTitleNode->appendChild($cdata);
//Replace the Existing CDATA Node
$node->parentNode->replaceChild($newTitleNode, $oldTitleNode);
}
}
|
T-SQL XML - how to divide CDATA in xml node
By : JNeo
Date : March 29 2020, 07:55 AM
will be helpful for those in need If you dont mind to have the first character with a precedding comma you could try this: code :
/*Loading test data*/
declare @xml varchar(8000)
set @xml = '
<value name="parameter">
<![CDATA[__na__]]>
<![CDATA[1]]>
<![CDATA[2]]>
<![CDATA[3]]>
<![CDATA[12]]>
</value>'
/*the replace*/
set @xml= REPLACE(@xml,'<![CDATA[','<![CDATA[,' )
select CAST(@xml AS XML)
<value name="parameter">,__na__ ,1 ,2 ,3 ,12 </value>
|
xsl:output using cdata-section-elements, does not encapsulate the targeted cdata-section-element in CDATA tag
By : Lise S
Date : March 29 2020, 07:55 AM
this will help The CDATA sections are not preserved as-is in a pipeline. However, the equivalent XML InfoSet is preserved. So for instance, if you escape an ampersand character using a CDATA section:
|
add CDATA to xml node
By : Boris Visser
Date : March 29 2020, 07:55 AM
may help you . DOM separates node create and append. You create the node using a method of the document and append it using methods of the parent node. Here is an example:
|