xml-parsing

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

两盒软妹~` 提交于 2019-12-29 08:27:29
问题 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('.

Parse XML on Android

有些话、适合烂在心里 提交于 2019-12-29 08:19:07
问题 I am trying to use the API for our billing system in an Android Application, but I am having trouble figuring out how to parse the XML that it returns. Here is what my function looks like thus far... public void ParseData(String xmlData) { try { // Document Builder DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder db = factory.newDocumentBuilder(); // Input Stream InputSource inStream = new InputSource(); inStream.setCharacterStream(new StringReader

Modify XML Parent Attributes iterating through Child attributes using powershell

我们两清 提交于 2019-12-29 08:18:45
问题 So I have the following xml (items.xml) and I want to find the attributes of the child node item iterate through the attributes and if I find similar attributes at parent node level replace the same with the child node attributes and remove the child attributes other than the name. <items> <model type="model1" name="default" price="12.12" date="some_value"> <PriceData> <item name="watch" price="24.28" date="2013-12-01" /> </PriceData> </model> <model type="model2" name="default" price="12.12"

Better way to detect XML?

与世无争的帅哥 提交于 2019-12-29 04:30:13
问题 Currently, I have the following c# code to extract a value out of text. If its XML, I want the value within it - otherwise, if its not XML, it can just return the text itself. String data = "..." try { return XElement.Parse(data).Value; } catch (System.Xml.XmlException) { return data; } I know exceptions are expensive in C#, so I was wondering if there was a better way to determine if the text I'm dealing with is xml or not? I thought of regex testing, but I dont' see that as a cheaper

Groovy XmlSlurper vs XmlParser

江枫思渺然 提交于 2019-12-29 02:39:48
问题 I searched for a while on this topic and found some results too, which I am mentioning at the end of post. Can someone help me precisely answer these three questions for the cases listed below them? For which use-cases using XmlSluper makes more sense than XmlParser and vice-versa (from point of view ease of use of API/Syntax)? Which one is more memory efficient? (looks like Slurper) which one processes the xml faster? Case a. when I have to read almost all nodes in the xml? Case b. when I

How to parse XML file using php

两盒软妹~` 提交于 2019-12-29 02:16:09
问题 I want to parse the following xml and get the value of metadata:description using php I know how to get the value of title $item_title = $x -> item($i) -> getElementsByTagName('title') -> item(0) -> childNodes -> item(0) -> nodeValue; but can not use this way to get metadata:description <item> <title>Jobs: Bullish Economy Confirmed?</title> <metadata:title xmlns:metadata="http://search.cnbc.com/rss/2.0/modules/siteContentMetadata">Jobs: Bullish Economy Confirmed? 06 Jan 2012</metadata:title>

Swift parsing attribute name for given elementName

一曲冷凌霜 提交于 2019-12-29 02:10:42
问题 Here is a part of my URL <cities> <country name="Абхазия"> <city id="37188" region="27028" head="" type="3" country="Абхазия" part="" resort="" climate="">Новый Афон</city> <city id="37178" region="10282" head="" type="3" country="Абхазия" part="" resort="" climate="">Пицунда</city> <city id="37187" region="37187" head="" type="3" country="Абхазия" part="" resort="" climate="">Гудаута</city> <city id="37172" region="10280" head="" type="3" country="Абхазия" part="" resort="" climate="">Гагра<

Parsing extremely large XML files in php

落爺英雄遲暮 提交于 2019-12-28 04:15:16
问题 I need to parse XML files of 40GB in size, and then normalize, and insert to a MySQL database. How much of the file I need to store in the database is not clear, neither do I know the XML structure. Which parser should I use, and how would you go about doing this? 回答1: In PHP, you can read in extreme large XML files with the XMLReaderDocs: $reader = new XMLReader(); $reader->open($xmlfile); Extreme large XML files should be stored in a compressed format on disk. At least this makes sense as

Where I can find a detailed comparison of Java XML frameworks?

你。 提交于 2019-12-28 03:21:12
问题 I'm trying to choose an XML-processing framework for my Java projects, and I'm lost in names.. XOM, JDOM, etc. Where I can find a detailed comparison of all popular Java XML frameworks? 回答1: As Blaise pointed out stick with the standards. But there are multiple standards created over the period to solve different problems/usecases. Which one to choose completely depends upon your requirement. I hope the below comparison can help you choose the right one. Now there are two things you have to

Extracting text after tag in Python's ElementTree

限于喜欢 提交于 2019-12-28 02:07:00
问题 Here is a part of XML: <item><img src="cat.jpg" /> Picture of a cat</item> Extracting the tag is easy. Just do: et = xml.etree.ElementTree.fromstring(our_xml_string) img = et.find('img') But how to get the text immediately after it ( Picture of a cat )? Doing the following returns a blank string: print et.text 回答1: Elements have a tail attribute -- so instead of element.text , you're asking for element.tail . >>> import lxml.etree >>> root = lxml.etree.fromstring('''<root><foo>bar</foo>baz<