xml-parsing

Java SAXParser parsing invalid xml [duplicate]

怎甘沉沦 提交于 2019-12-11 00:53:09
问题 This question already has answers here : How to parse invalid (bad / not well-formed) XML? (4 answers) Closed 2 years ago . I'm trying to parse some xml which is invalid as the attributes are not in quotes, is there any way of getting around this? A simple example of this below, as well as the java code. XML <car id=1> . . </car> Java SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(false); SAXParser saxParser = factory.newSAXParser(); saxParser.parse(page,

Reading XML value to populate Java variable

六月ゝ 毕业季﹏ 提交于 2019-12-11 00:49:10
问题 I am working with xstream to convert some XML into Java objects. The XML pattern is of the below format: <Objects> <Object Type="System.Tuning" >4456</Object> <Object Type="System.Lag" >7789</Object> </Objects> Basically the parent Objects tag can have n number of Object tags. For this I have modelled my class like this: class ParentResponseObject { List <ResponseObject>responseObjects = new ArrayList<ResponseObject>(); public ParentResponseObject() { // TODO Auto-generated constructor stub }

Groovy XmlSlurper parse mixed text and nodes

橙三吉。 提交于 2019-12-11 00:42:14
问题 I'm currently trying to parse a node in groovy which contains mixed text and nodes with text and I need to get the text in the right order for example: <?xml version="1.0" encoding="UTF-8"?> <root> <p> The text has <strong>nodes</strong> which need to get parsed </p> </root> Now I want it to parse so I get the whole text but can still edit the node. In this example I want the result: The text has <b>nodes</b> which need to get parsed If I could just get a list of all elements under the p

Parser for xml DTD file

谁说胖子不能爱 提交于 2019-12-11 00:36:42
问题 I am quite new in implementing a parser and I am trying to pars a xml DTD file to generate a context free grammar for it. I tried pyparsing and yacc but still I could get any result. So I would appreciate if some one could provide me some tips or sample code to write such a parser. following is a sample DTD file: <!DOCTYPE PcSpecs [ <!ELEMENT PCS (PC*)> <!ELEMENT PC (MODEL, PRICE, PROCESSOR, RAM, DISK+)> <!ELEMENT MODEL (\#PCDATA)> <!ELEMENT PRICE (\#PCDATA)> <!ELEMENT PROCESSOR (MANF, MODEL,

T-SQL: cross apply; too many iterations on line items

拜拜、爱过 提交于 2019-12-11 00:25:33
问题 I've almost got what I want after shredding up some serious Xml--but after looking at the results, I see that in one section of the parsing, I can't easily resolve this pattern of iterating through all of the line details for each of the subheaders-- so instead of writing out a total of let's say 3 records for all of the line items, I'm writing out three line items for each of the subs--of which let's say I have two. I wind up with a total of 6! :-( I've distilled the pattern as a generic

XSLT to deep sort any generic XML on element names

旧时模样 提交于 2019-12-11 00:06:13
问题 I was wondering if it's possible to deep sort an XML (with attributes) on element names without knowing the structure of the XML or the element names. The sorting should be only based on XML Elements and not the attributes. Thanks Example XML: <Customer> <CustomerID>ALFKI</CustomerID> <Order> <OrderID>10692</OrderID> <CustomerID>ALFKI</CustomerID> <OrderDate>1997-10-03</OrderDate> </Order> <CompanyName>Alfreds Futterkiste</CompanyName> </Customer> Result Expected: <Customer> <CompanyName

Omitting XML Declaration when invoking Transformer with StAXResult

自作多情 提交于 2019-12-10 23:49:20
问题 I would like to copy multiple XML nodes from a source XML file to a target file. Both source and target files are very large, so I will use StAX. Typically the file I'm trying to process looks as follows: <root> <header> <title>A List of persons</title> </header> <person> <name>Joe</name> <surname>Bloggs</surname> </person> <person> <name>John</name> <surname>Doe</surname> </person> . . etc... </root> The target files should be in the following format: <root> <header> <title>A List of persons

Getting a memory error when parsing a large XML file in Python

大兔子大兔子 提交于 2019-12-10 23:43:24
问题 My XML file looks like this: <root> <group from="1", to="100"> <link target="1"/> ... <link target="100"/> </group> ... </root> I have a 6000 <group> elements and 5M <link> elements. I want to have a dictionary with the tuple ( from , to ) as keys and a list of <link> s' target attributes, but I get a memory error with following code: from lxml import etree from gzip import open as gopen def extractTargets(fin): targets = dict() with gopen(fin) as xml: context = etree.iterparse(xml, tag=

Parsing XML attributes in java

蓝咒 提交于 2019-12-10 23:37:04
问题 I have an xml similar to this <Applications> <ApplicationID> <VendorId value="0" /> <AuthApplId value="4" /> <AcctApplId value="0" /> </ApplicationID> <ApplicationID> <VendorId value="193" /> <AuthApplId value="0" /> <AcctApplId value="19302" /> </ApplicationID> </Applications> I want to parse this and store to Strings Like VendorId, AuthApplId etc. I got ApplicationID parsed with getElementsByTagName("ApplicationID") if it was <ApplicationID value="somevalue"/> then I can use getAttribute(

Xml Parser unexpected token error position:TEXT @1:2 in java.io.StringReader

微笑、不失礼 提交于 2019-12-10 23:01:08
问题 The problem is when I parse the XML from the original link for example (I am not posting the original link due to security purpose) http://example.com/ss.svc/APIabc?A=10&Key=XXXXX&From=19&To=221&Date=19-Apr-2016 then listview is not populated and the the logcat says error this LogCat error- Unexpected token (position:TEXT @1:2 in java.io.StringReader@4255df00) Shutting down VM threadid=1: thread exiting with uncaught exception (group=0x41b19438) FATAL EXCEPTION: main java.lang