cdata

read cdata from a rss feed

十年热恋 提交于 2019-11-27 08:38:56
问题 I'm reading a rss feed using simple code: <?php $homepage = file_get_contents('http://www.forbes.com/news/index.xml'); $movies = new SimpleXMLElement($homepage); echo '<pre>'; print_r($movies); ?> and the output like this: SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 ) [channel] => SimpleXMLElement Object ( [title] => SimpleXMLElement Object ( ) [link] => SimpleXMLElement Object ( ) [description] => SimpleXMLElement Object ( ) [language] => en-us [copyright] =>

Force use of CDATA in XML-schema

隐身守侯 提交于 2019-11-27 06:19:43
问题 I am creating an xml schema, and I want to make sure that the values in all the elements are CDATA elements. Is there a way to force this using XML-schema? 回答1: As I recall XML Schema works on the XML Infoset, meaning with the XML document after it is parsed, entities are resolved, whitespace is normalised and CDATA is processed. CDATA is a way of easing the textual serialization not a part of the structural model. So: No. Neither in DTDs or RELAX NG. 来源: https://stackoverflow.com/questions

Strip whitespace and newlines from XML in Java

妖精的绣舞 提交于 2019-11-27 05:25:23
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/test.xml")); Writer out = new StringWriter(); Transformer tf = TransformerFactory.newInstance()

java.lang.IllegalStateException: CDATA tags may not nest

淺唱寂寞╮ 提交于 2019-11-27 01:27:43
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.java:342) at org.primefaces.context.PrimePartialResponseWriter.startError(PrimePartialResponseWriter.java

How to write CDATA using SimpleXmlElement?

别等时光非礼了梦想. 提交于 2019-11-27 00:40:17
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"><![CDATA[Site Title]]></title> </site> quantme Got it! I adapted the code from this great solution : <?php // http://coffeerings

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

 ̄綄美尐妖づ 提交于 2019-11-27 00:38:21
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 .net web service, were it will be parsed back. Therefore I need to be able to export the xml as a string

Using CDATA inside another CDATA

我怕爱的太早我们不能终老 提交于 2019-11-26 23:14:15
问题 I have this difficult situation where I need to use the CDATA tags inside another CDATA tags. The situation is simple to explain though. I have the following thing: <edit> <![CDATA[ <script type="text/javascript"> <![CDATA[ window.onload = function() { document.getElementById('block').onclick = function() { this.onclick = ''; this.value = '{LA_SEND_CONFIRM}'; this.className = this.className.replace('button1',''); document.getElementById('replacement').value = '{LA_BLOCK_CODE}'; } } ]]> <

How can i grab CData out of BeautifulSoup

核能气质少年 提交于 2019-11-26 23:10:33
问题 I have a website that I'm scraping that has a similar structure the following. I'd like to be able to grab the info out of the CData block. I'm using BeautifulSoup to pull other info off the page, so if the solution can work with that, it would help keep my learning curve down as I'm a python novice. Specifically, I want to get at the two different types of data hidden in the CData statement. the first which is just text I'm pretty sure I can throw a regex at it and get what I need. For the

Using NSXMLParser with CDATA

十年热恋 提交于 2019-11-26 22:58:55
问题 I'm parsing an RSS feed with NSXMLParser and it's working fine for the title and other strings but one of the elements is an image thats like <!CDATA <a href="http:image..etc> How do I add that as my cell image in my table view? Would I define that as an image type? This is what i'm using to do my parsing: - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{

How to parse XML for <![CDATA[]]>

旧城冷巷雨未停 提交于 2019-11-26 21:24:09
问题 How to parse a XML having data included in <![CDATA[---]... how can we parse the xml and get the data included in CDATA ??? 回答1: public static void main(String[] args) throws Exception { File file = new File("data.xml"); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); //if you are using this code for blackberry xml parsing builder.setCoalescing(true); Document doc = builder.parse(file); NodeList nodes = doc.getElementsByTagName("topic"); for (int i = 0; i