cdata

Figuring out where CDATA is in lxml element?

自古美人都是妖i 提交于 2019-12-22 11:18:12
问题 I need to parse and rebuild a file format used by a parser which speaks a language that can only charitably be described as XML. I realize that standards-compliant XML doesn't care about either the CDATA or the whitespace, but unfortunately this application demands that I care about both... I'm using lxml.etree because it's pretty good at preserving CDATA. For example: s = ''' <root> <item> <![CDATA[whatever]]> </item> </root>''' import lxml.etree as et et.fromstring(s, et.XMLParser(strip

If Statement not working with And (&&) Operator

大憨熊 提交于 2019-12-22 10:53:34
问题 I'm having a hard time writing up what seems should be a simple if statement! I need it to say if mod does not equal a, b, or c - then do this. Here is what I was trying but have been unsuccessful: var mod = CURRENT_MODULE_ID; if (mod != "5827289" && mod != "5195103" && mod != "5181422") { doSomething(); } When I type this into my editor it says there is an error, specifically that "The entity name must immediately follow the '&' in the entity reference." .. and is not working when I go to

LXML kills my CDATA sections

妖精的绣舞 提交于 2019-12-22 04:17:24
问题 I'm batch-converting a lot of XML files, changing their character encodings to UTF-8: with open(source_filename, "rb") as source: tree = etree.parse(source) with open(destination_filename, "wb") as destination: tree.write(destination, encoding="UTF-8", xml_declaration=True) Unfortunately, it is destroying my CDATA sections and just escaping them instead. Source : <d><![CDATA[áÌÀøÅàùÑÄéú ëÌÄé áÈàÅùÑ éäå''ä ðÄùÑÀôÌÈè <small><small>(ùí ëå èæ)</small></small> Destination : <d>בְּרֵאשִׁית כִּי בָאֵשׁ

cdata in xslt for html

限于喜欢 提交于 2019-12-21 22:18:21
问题 I have an XSLT file generating plain HTML. I need to wrap some elements in CDATA blocks, so intend to use cdata-section-elements. But, if the element I want to have contain CDATA is only one <p> on the page, how do I get it to not put CDATA in all the other <p> elements? The input data is this: <item> ... <g:category>Gifts under &pound;10</g:category> </item> My XSL is: <xsl:element name="a"> <xsl:attribute name="href">productlist.aspx</xsl:attribute> <xsl:copy-of select="text()" /> </xsl

Which is better for encoding HTML for RSS?

五迷三道 提交于 2019-12-21 20:06:07
问题 I recently introduced HTML into some RSS feeds that I publish (which up to now only had plain text, no markup), and I was wondering which method is better: use character encoding (such as htmlspecialchars) or just encapsulate everything in CDATA? It seems to me that CDATA might be easier, but I'm unclear as to whether there might be any reasons (subtle or otherwise) for choosing one approach versus the other. (For starters, the CDATA approach would be easier to read when viewing source...)

How to remove `//<![CDATA[` and end `//]]>`?

為{幸葍}努か 提交于 2019-12-21 03:44:07
问题 How can I remove the (//<![CDATA[ , //]]> ) blocks; tags inside a script element. <script type="text/javascript"> //<![CDATA[ var l=new Array(); .......................... .......................... //]]> </script> Looks like it can be done with preg_replace() but havent found a solution that works for me. What regex would I use? 回答1: The following regex will do it... $removed = preg_replace('/^\s*\/\/<!\[CDATA\[([\s\S]*)\/\/\]\]>\s*\z/', '$1', $scriptText); CodePad. 回答2: You don't need regex

How to access variable in CDATA from XSLT?

倖福魔咒の 提交于 2019-12-19 22:25:04
问题 I am using XSLT Transformation and need to put some data in CDATA section and that vale is present in a variable. Query: How to access variable in CDATA ? Sample Given Below: <xsl:attribute name ="attributeName"> <![CDATA[ I need to access some variable here like *<xsl:value-of select ="$AnyVarible"/>* ]]> </xsl:attribute> How can I use varibale in CDATA ? Note: I can not use --> <![CDATA[<xsl:value-of select ="$AnyVarible"/>]]> Thanks in advance. 回答1: I got the solution for this...FYI for

How to remove `//<![CDATA[` and end `//]]>` with javascript from string?

妖精的绣舞 提交于 2019-12-19 17:16:31
问题 How to remove //<![CDATA[ and end //]]> with javascript from string? var title = "<![CDATA[A Survey of Applications of Identity-Based Cryptography in Mobile Ad-Hoc Networks]]>" ; needs to become var title = "A Survey of Applications of Identity-Based Cryptography in Mobile Ad-Hoc Networks"; How to do that? 回答1: You can use the String.prototype.replace method, like: title = title.replace("<![CDATA[", "").replace("]]>", ""); This will replace each target substring with nothing. Note that this

Stop WordPress from enclosing script in CDATA

心不动则不痛 提交于 2019-12-19 08:44:38
问题 I am importing HTML pages using HTML import plugin for WordPress. I have a code snippet for google maps, which is imported. However, after import, it encloses the script tag in CDATA . If I remove CDATA, the map works fine. How do I stop WordPress from enclosing the script with CDATA? Here's the script : <script type="text/javascript"> <[[CDATA[ var locations = [ ['<strong>Alabama', 33.606379, -86.50249, 1] ]; var map = new google.maps.Map(document.getElementById("map"), { zoom: 5, center:

Stop WordPress from enclosing script in CDATA

别说谁变了你拦得住时间么 提交于 2019-12-19 08:42:11
问题 I am importing HTML pages using HTML import plugin for WordPress. I have a code snippet for google maps, which is imported. However, after import, it encloses the script tag in CDATA . If I remove CDATA, the map works fine. How do I stop WordPress from enclosing the script with CDATA? Here's the script : <script type="text/javascript"> <[[CDATA[ var locations = [ ['<strong>Alabama', 33.606379, -86.50249, 1] ]; var map = new google.maps.Map(document.getElementById("map"), { zoom: 5, center: