xml-parsing

lxml.objectify and leading zeros

此生再无相见时 提交于 2019-12-24 02:09:11
问题 When the objectify element is printed on the console, the leading zero is lost, but it is preserved in the .text : >>> from lxml import objectify >>> >>> xml = "<a><b>01</b></a>" >>> a = objectify.fromstring(xml) >>> print(a.b) 1 >>> print(a.b.text) 01 From what I understand, objectify automatically makes the b element an IntElement class instance. But, it also does that even if I try to explicitly set the type with an XSD schema: from io import StringIO from lxml import etree, objectify f =

get the attributes from an XML File using Java

安稳与你 提交于 2019-12-24 01:11:08
问题 I have an XML file with this structure: <?xml version="1.0"> <person> <element att1="value1" att2="value2">Anonymous</element> </person> How can I extract the attributes names and values using wathever you want. I tried JDOM, but I still can't find a way to get the attributes from the element. Element root = doc.getRootElement(); List allChildren = root.getChildren(); Iterator i = listEtudiants.iterator(); while(i.hasNext()) { Element current = (Element)i.next(); System.out.println(current

simplexml_load_file Document is empty

僤鯓⒐⒋嵵緔 提交于 2019-12-24 00:43:24
问题 I'm pulling from a RSS feed: http://search.library.utoronto.ca/UTL/index?Ntt=starcraft&Ntk=Anywhere&Ntx=mode+matchallpartial&N=0&Nu=p_work_normalized&Np=1&rss=1 If you navigate to that with a browser, you get a nice xml page. However, if I do simplexml_load_file("the above url"); in php, I get 1: parser error : Document is empty 1: parser error : Start tag expected, '<' not found in my_file So why can the browser get it but not PHP? If I do file_get_contents("the above url") the function

How to read key/value in xml file

有些话、适合烂在心里 提交于 2019-12-24 00:17:46
问题 I am trying to build a console project which reads an ASP.NET project's web.config file. I need to read a value from the config. I am putting what I want to read from the web.config file. <appSettings> <add key="LogoFrmNumber" value="001"/> <add key="LogoFrmPeriod" value="01"/> </appSettings> I want to read LogoFrmNumber's value like I read regular xml file. How can I read that value. here is my code to read web.config but I am stuck. XDocument doc = XDocument.Load( "c://web.config" ); var

Parse XML file to fetch required data and store it in mongodb database in Python

落爺英雄遲暮 提交于 2019-12-23 21:06:35
问题 I have an XML file which looks like this: XML File I want to fetch following information from this file for all the events: Under category event: start_date end_date title Under category venue: address address_2/ city latitude longitude name postal_code and then store this information in a mongodb database. I don't have much experience in parsing. Can someone please help me with this! Thanks ! 回答1: from pymongo import MongoClient import xml.etree.ElementTree as ET from urllib2 import urlopen

How to remove unwanted tags from XML

最后都变了- 提交于 2019-12-23 21:05:48
问题 I have a huge XML and I want to remove unwanted tags from this. Ex.' <orgs> <org name="Test1"> <item>a</item> <item>b</item> </org> <org name="Test2"> <item>c</item> <item>b</item> <item>e</item> </org> </orgs> I want to remove all the <item>b</item> from this xml. Which parser api should be use for this as xml is very large and How can achieve it. 回答1: One approach would be to use a Document Object Model (DOM), the draw back to this, as the name suggests, it needs to load the entire document

Get URL from media:content in RSS XML feed with jQuery

那年仲夏 提交于 2019-12-23 19:51:16
问题 I am trying to retrieve the images (along with other content) from media:content for each post in an RSS feed: http://bits.blogs.nytimes.com/feed/ I tried this link (along with many others) jQuery XML parsing how to get element attribute but I am still getting errors. There is a PHP file as well (see at bottom) but I don't think that it is the issue. I have tried several variations and I am ending up with <img src="undefined" alt="image"> This is what the log is saying TypeError: 'undefined'

XmlPullParser get file from filesystem

你说的曾经没有我的故事 提交于 2019-12-23 18:23:20
问题 I my app creater xml file in Android file system. I ned parse this file with XmlPullParser, but I get error wile compilation: "variable parser might not have been initialized". My code: InputStream inputStream = openFileInput("settings.xml"); XmlPullParser parser; parser.setInput(inputStream, null); Have no idea, how to repair it. I use Intellij IDEA12 and Android 2.3 SDK. 回答1: I use Eclipse and the below code has worked for me: You might be missing the below first line: XmlPullParserFactory

XML Schema. Processing namespace-aware attribute values

青春壹個敷衍的年華 提交于 2019-12-23 18:11:12
问题 Part of my project involves heavy transformations of user-defined schema documents. I need to be able to change target namespaces, support type cross-references and build wsdl upon multiple schema documents. One of the most commonly used operations is changing namespace prefix prior to importing schema into wsdl file. I'm using org.xml.sax.ContentHandler and it's startPrefixMapping method to handle namespaces. All works fine and flawless unless I want to change element types. Here is simple

Android, org.w3c.dom: No validating DocumentBuilder implementation available

会有一股神秘感。 提交于 2019-12-23 18:07:43
问题 I'm trying to parse an XML document on Android 2.3.3, but it seems that there is no validating parser. The reason I need validation for is to ignore whitespaces in the XML file (blanks, carriage returns, line feeds, etc.). Thats how I want to parse the document: DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); dbfac.setValidating(true); dbfac.setIgnoringElementContentWhitespace(true); DocumentBuilder docBuilder; docBuilder = dbfac.newDocumentBuilder(); Document d =