cdata

what xpath to select CDATA content when some childs exist

萝らか妹 提交于 2019-11-29 15:10:01
Let's say I have an XML that looks like this: <a> <b> <![CDATA[some text]]> <c>xxx</c> <d>yyy</d> </b> </a> I can't find a way to get "some text". Any idea? If I'm using "a/b" it returns also xxx and yyy If I'm using "a/b/text()" it returns nothing You can't actually select a CDATA section: CDATA is just a way of telling the parser to avoid unescaping special characters, and your input document looks to XPath exactly the same as: <a> <b> some text <c>xxx</c> <d>yyy</d> </b> </a> (Having said that, if you're using DOM, then some DOM XPath engines fail to implement the spec correctly, and treat

trying to get content inside cdata tags in xml file using nokogiri

自作多情 提交于 2019-11-29 13:12:28
I have seen several things on this, but nothing has seemed to work so far. I am parsing an xml via a url using nokogiri on rails 3 ruby 1.9.2. A snippet of the xml looks like this: <NewsLineText> <![CDATA[ Anna Kendrick is ''obsessed'' with 'Game of Thrones' and loves to cook, particularly creme brulee. ]]> </NewsLineText> I am trying to parse this out to get the text associated with the NewsLineText r = node.at_xpath('.//newslinetext') if node.at_xpath('.//newslinetext') s = node.at_xpath('.//newslinetext').text if node.at_xpath('.//newslinetext') t = node.at_xpath('.//newslinetext').content

How do i write the literal “]]>” inside a CDATA section without it ending the section

谁都会走 提交于 2019-11-29 09:45:48
Pretty simple question, I'm writing an XML document and i'm not sure how to write "]]>" without it being seen as the end of the section. You can do it like this: ]]>]]><![CDATA[ This ends up breaking the CDATA section in two parts, but it's what you have to do. Henrik Paul I think <![CDATA[]]]]><![CDATA[>]]> is the way to go. That is: one CDATA section containing the literal string ]] ( <![CDATA[]]]]> ) one CDATA section containing the literal string > ( <![CDATA[>]]> ) In practice, there would probably be text before the first ]] and/or after the > See more at http://en.wikipedia.org/wiki

Parsing CDATA in android

╄→гoц情女王★ 提交于 2019-11-29 08:16:45
I'm parsing XML which is on the server I read it and parse it There is no any error But I'm unable to see the data. Here is my XML: <BookData><book><Title><![CDATA[ABC]]></Title><AuthorFName1><![CDATA[A]]></AuthorFName1><AuthorLName1><![CDATA[B]]></AuthorLName1></book><book><Title><![CDATA[XYZ]]></Title><AuthorFName1><![CDATA[A]]></AuthorFName1><AuthorLName1><![CDATA[B]]></AuthorLName1></book> I'm using DocumentBuilderFactory see the code even I set dbf.setCoalescing(true); But still not working please see the code for DocumentBuilderFactory Document doc = null; DocumentBuilderFactory dbf =

Can CDATA sections be preserved by BeautifulSoup?

ぐ巨炮叔叔 提交于 2019-11-29 07:49:32
I'm using BeautifulSoup to read, modify, and write an XML file. I'm having trouble with CDATA sections being stripped out. Here's a simplified example. The culprit XML file: <?xml version="1.0" ?> <foo> <bar><![CDATA[ !@#$%^&*()_+{}|:"<>?,./;'[]\-= ]]></bar> </foo> And here's the Python script. from bs4 import BeautifulSoup xmlfile = open("cdata.xml", "r") soup = BeautifulSoup( xmlfile, "xml" ) print(soup) Here's the output. Note the CDATA section tags are missing. <?xml version="1.0" encoding="utf-8"?> <foo> <bar> !@#$%^&*()_+{}|:"<>?,./;'[]\-= </bar> </foo> I also tried printing soup

Thymeleaf and inline scripts SAXParseException

我怕爱的太早我们不能终老 提交于 2019-11-29 07:10:15
I got a page which uses thymeleaf template, and I'm getting the following error on page load when using inline scripts: org.xml.sax.SAXParseException; lineNumber: 270; columnNumber: 85; The content of elements must consist of well-formed character data or markup. Code at line 270 <script type="text/javascript" > window.jQuery || document.write("<script src='assets/js/jquery-2.0.3.min.js'>"+"<"+"/script>"); </script> I have tried replacing "<", ">" symbols from document.write with < > , the exception doesn't occur anymore but the script is not loaded anymore You need to add CDATA tags for the

SQL Server XML output with CDATA

a 夏天 提交于 2019-11-29 07:00:38
Is there a way to have an SQL Server XML return use CDATA? I have XML being returned by SQL Server like this: <locations> <site id="124"> <sitename>Texas A & M</sitename> </site> </locations> When I am required to have this: <locations> <site id="124"> <sitename><![CDATA[Texas A & M]]></sitename> </site> </locations> Lukasz Lysik Look at the options of FOR XML EXPLICIT (parameter Directive ). It gives the greater degree of control and you can also specify CDATA. Here is a good tutorial . And the code addapted from that tutorial: declare @agent table ( AgentID int, Fname varchar(5), SSN varchar

Storing base64 data in XML?

匆匆过客 提交于 2019-11-29 05:24:15
How I can store base64 strings in XML? Do you use CDATA to store base64 strings in XML? Would it help as it allows use of < > within the strings? Is base64 configurable where you tell it not to use certain chars if they conflict with XML? You can just store it as a text or attribute value; no escaping or CDATA sections needed. The standard base 64 characters + and / (other than a-z , A-Z and 0-9 ) do not interfere with XML parsing at all. Base64 only uses alphanumeric characters and '+' (plus), '/' (slash) and '=' (equals). No need to encode anything for XML. Anton Gogolev There are no

.Net XmlSerializer: deserialize CDATA being inner text

邮差的信 提交于 2019-11-29 04:33:11
I have a problem with CDATA deserialization using standard .Net XmlSerializer. Update : I get XML from external system and I can't influence it's format so I can't make CData be enclosed in a separate Element of Attribute. Serialization gives this: <?xml version="1.0" encoding="utf-16"?> <MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><![CDATA[Hello, world!]]></MyClass> Deserialization does not restore object to it's original state. Here's class that is being serialized: public class MyClass { string _data; [XmlIgnore] public string

Decode CDATA section in C#

十年热恋 提交于 2019-11-29 01:52:23
I have a bit of XML as follows: <section> <description> <![CDATA[ This is a "description" that I have formatted ]]> </description> </section> I'm accessing it using curXmlNode.SelectSingleNode("description").InnerText but the value returns \r\n This is a "description"\r\n that I have formatted instead of This is a "description" that I have formatted. Is there a simple way to get that sort of output from a CDATA section? Leaving the actual CDATA tag out seems to have it return the same way. You can use Linq to read CDATA. XDocument xdoc = XDocument.Load("YourXml.xml"); xDoc.DescendantNodes()