cdata

Strip whitespace and newlines from XML in Java

孤者浪人 提交于 2019-11-26 17:51:03
问题 Using Java, I would like to take a document in the following format: <tag1> <tag2> <![CDATA[ Some data ]]> </tag2> </tag1> and convert it to: <tag1><tag2><![CDATA[ Some data ]]></tag2></tag1> I tried the following, but it isn't giving me the result I am expecting: DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); dbfac.setIgnoringElementContentWhitespace(true); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document doc = docBuilder.parse(new FileInputStream("/tmp

How can I retain CDATA tags when storing query results in an Xml variable?

柔情痞子 提交于 2019-11-26 17:25:22
问题 When I generate Xml in Sql Server 2008 R2 using For Explicit (because my consumer wants one of the elements wrapped in CDATA) and store the results in an Xml variable, the data I want wrapped in CDATA tags no longer appears wrapped in CDATA tags. If I don't push the For Xml Explicit results into an Xml variable then the CDATA tags are retained. I am using the @Xml variable as an SqlParameter from .Net. In this example, the first select (Select @Xml) does not have Line2 wrapped in CDATA tags.

How to generate CDATA block using JAXB?

六眼飞鱼酱① 提交于 2019-11-26 15:19:39
I am using JAXB to serialize my data to XML. The class code is simple as given below. I want to produce XML that contains CDATA blocks for the value of some Args. For example, current code produces this XML: <command> <args> <arg name="test_id">1234</arg> <arg name="source"><html>EMAIL</html></arg> </args> </command> I want to wrap the "source" arg in CDATA such that it looks like below: <command> <args> <arg name="test_id">1234</arg> <arg name="source"><[![CDATA[<html>EMAIL</html>]]></arg> </args> </command> How can I achieve this in the below code? @XmlRootElement(name="command") public

Is there a way to escape a CDATA end token in xml?

不问归期 提交于 2019-11-26 11:42:55
I was wondering if there is any way to escape a CDATA end token ( ]]> ) within a CDATA section in an xml document. Or, more generally, if there is some escape sequence for using within a CDATA (but if it exists, I guess it'd probably only make sense to escape begin or end tokens, anyway). Basically, can you have a begin or end token embedded in a CDATA and tell the parser not to interpret it but to treat it as just another character sequence. Probably, you should just refactor your xml structure or your code if you find yourself trying to do that, but even though I've been working with xml on

What is CDATA in HTML? [duplicate]

若如初见. 提交于 2019-11-26 11:36:51
This question already has an answer here: When is a CDATA section necessary within a script tag? 15 answers What is the use of CDATA inside JavaScript tags and HTML? <script type="text/javascript"> // <![CDATA[ // ]]> </script> Ahsan Rathod All text in an XML document will be parsed by the parser. But text inside a CDATA section will be ignored by the parser. CDATA - (Unparsed) Character Data The term CDATA is used about text data that should not be parsed by the XML parser. Characters like "<" and "&" are illegal in XML elements. "<" will generate an error because the parser interprets it as

PHP, SimpleXML, decoding entities in CDATA

孤人 提交于 2019-11-26 09:57:32
问题 I\'m experiencing the following behavior: $xml_string1 = \"<person><name><![CDATA[ Someone's Name ]]></name></person>\"; $xml_string2 = \"<person><name> Someone's Name </name></person>\"; $person = new SimpleXMLElement($xml_string1); print (string) $person->name; # Someone's Name $person = new SimpleXMLElement($xml_string2); print (string) $person->name; # Someone\'s Name $person = new SimpleXMLElement($xml_string1, LIBXML_NOCDATA); print (string) $person->name; # Someone's Name The php docs

java.lang.IllegalStateException: CDATA tags may not nest

╄→гoц情女王★ 提交于 2019-11-26 09:39:49
问题 I\'ve got a problem with an ajax request in a JSF page. When I click on the button, I get this exception: SEVERE: Servlet.service() for servlet Faces Servlet threw exception java.lang.IllegalStateException: CDATA tags may not nest at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startCDATA(HtmlResponseWriter.java:630) at javax.faces.context.ResponseWriterWrapper.startCDATA(ResponseWriterWrapper.java:172) at javax.faces.context.PartialResponseWriter.startError(PartialResponseWriter

Html inside XML. Should I use CDATA or encode the HTML

送分小仙女□ 提交于 2019-11-26 09:27:02
问题 I am using XML to share HTML content. AFAIK, I could embed the HTML either by: Encoding it: I don\'t know if it is completely safe to use. And I would have to decode it again. Use CDATA sections: I could still have problems if the content contains the closing tag \"]]>\" and certain hexadecimal characters, I believe. On the other hand, the XML parser would extract the info transparently for me. Which option should I choose? UPDATE: The xml will be created in java and passed as a string to a

How to write CDATA using SimpleXmlElement?

不羁岁月 提交于 2019-11-26 09:25:34
问题 I have this code to create and update xml file: <?php $xmlFile = \'config.xml\'; $xml = new SimpleXmlElement(\'<site/>\'); $xml->title = \'Site Title\'; $xml->title->addAttribute(\'lang\', \'en\'); $xml->saveXML($xmlFile); ?> This generates the following xml file: <?xml version=\"1.0\"?> <site> <title lang=\"en\">Site Title</title> </site> The question is: is there a way to add CDATA with this method/technique to create xml code below? <?xml version=\"1.0\"?> <site> <title lang=\"en\"><!

How to generate CDATA block using JAXB?

拈花ヽ惹草 提交于 2019-11-26 04:19:54
问题 I am using JAXB to serialize my data to XML. The class code is simple as given below. I want to produce XML that contains CDATA blocks for the value of some Args. For example, current code produces this XML: <command> <args> <arg name=\"test_id\">1234</arg> <arg name=\"source\"><html>EMAIL</html></arg> </args> </command> I want to wrap the \"source\" arg in CDATA such that it looks like below: <command> <args> <arg name=\"test_id\">1234</arg> <arg name=\"source\"><[![CDATA[<html>EMAIL</html>]