sax

Passing XML resource to XMLReader

一个人想着一个人 提交于 2019-12-10 18:45:21
问题 I am trying to pass a .xml file from my res folder to an XMLReader in order to parse it to an object: private void parseXML() { String parsedData = ""; try { Log.w("AndroidParseXMLActivity", "Start"); /** Handling XML */ SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); QuestionXMLHandler myXMLHandler = new QuestionXMLHandler(); xr.setContentHandler(myXMLHandler); InputSource inStream = new InputSource(); Log.w(

How to read large XML file consisting of large number of small items efficiently in Java?

匆匆过客 提交于 2019-12-10 18:38:15
问题 I have a large XML file that consists of relatively fixed size items i.e. <rootElem> <item>...</item> <item>...</item> <item>...</item> <rootElem> The item elements are relatively shallow and typically rather small ( <100 KB), but there may be a lot of them (hundreds of thousands). The items are completely independent of each other. How could I process the file efficiently in Java? I can't read the whole file in as DOM, and I don't like to use SAX because the code gets rather complex. I'd

Is there a way to parse XML via SAX/DOM with line numbers available per node

时光毁灭记忆、已成空白 提交于 2019-12-10 13:58:18
问题 I already have written a DOM parser for a large XML document format that contains a number of items that can be used to automatically generate Java code. This is limited to small expressions that are then merged into a dynamically generated Java source file. So far - so good. Everything works. BUT - I wish to be able to embed the line number of the XML node where the Java code was included from (so that if the configuration contains uncompilable code, each method will have a pointer to the

How to get the attribute value in the SAX parser

自古美人都是妖i 提交于 2019-12-10 12:25:55
问题 I have use the SAXParser to read the xml format. Then the startelement method run but I have no idea how to get the url in the method. I dont know what is the solution. Thank you <enclosure length="1234567" type="image/jpeg" url="http://www.nasa.gov/images/content/664322main_31_lands_cropped_516-387.jpg"/> 回答1: What language? What implementation? It is always a good idea to at least tag which language you are trying to implement in. The idea is to iterate through the attributes parameter in

XML Empty tags using Sax parsing

不羁的心 提交于 2019-12-10 12:08:10
问题 how to find or separate the empty xml strings in SAX Parsing. <Table diffgr:id="Table142" msdata:rowOrder="141"> <TeamIDGiven>7</TeamIDGiven> <City>Wolfpack</City> <TeamName>North Carolina State</TeamName> </Table> <Table diffgr:id="Table143" msdata:rowOrder="142"> <TeamIDGiven>308</TeamIDGiven> **<City/>** <TeamName>North Dakota</TeamName> </Table> <Table diffgr:id="Table144" msdata:rowOrder="143"> <TeamIDGiven>309</TeamIDGiven> <City>Bison</City> <TeamName>North Dakota State</TeamName> <

How to read escaped characters using SAX parser in Characters method?

做~自己de王妃 提交于 2019-12-10 11:56:52
问题 I'm parsing the following XML using parser: <Person> <Name>Test</Name> <Phone>111-111-2222</OtherPhone> <Address>lee h&y</Address> <Person> The characters method of the sax parser is only reading the address data until 'lee h' as it does not consider '&' as a character. I need to get the complete text in the address element. Any ideas on how I should do it? This is my sax parser(here address is a flag which notifies that an address element is present in XML): boolean address=false; public

JAVA SAX DefaultHandler startCDATA() not firing

ⅰ亾dé卋堺 提交于 2019-12-10 11:23:27
问题 I am trying to parse and detect the start of the CDATA within a tag like: <child><![CDATA[data goes here]]></child> I have a class that extends the Default handler class MyXmlDoc extends DefaultHandler{ with methods for startElement() and endElement() that fire correctly but the startCDATA() never fires. My characters() method picks up the 'data goes here' so it appears that the CDATA 'wrapper' is detected but ??? Thanks for any insight! 回答1: CDATA is a lexical event. Regular handlers

StAX - reading base64 string from xml into db

穿精又带淫゛_ 提交于 2019-12-10 10:35:16
问题 I'm using StAX to read my file, which has some Base64 data in it, and saving it into the db using Hibernate. XML: <root> <base64>lololencoded12</base64> <base64>encodedlolos32</base64> ............................... </root> Code to read and save: xmlif = (XMLInputFactory2) XMLInputFactory2.newInstance(); xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); xmlif.setProperty

iOS: Combining SAX and DOM parsing

混江龙づ霸主 提交于 2019-12-10 10:34:49
问题 I am currently working on an iPad project for which I need to process large XML file into an SQLite backend. I currently have this working using the TBXML parser. So all the logic is in place and in general the TBXML parser does the job it needs to do. Only problem I'm now encountering is that the XML files are getting too big and I am running out of memory. Because of this I thinking of switching to a SAX parser like the core NSXMLParser of something like Alan Quatermain's AQXMLParser.

What is the right way to get attribute value in libXML sax parser (C++)?

巧了我就是萌 提交于 2019-12-10 10:02:46
问题 I am using the SAX interface of libXML to write a XML parser application in C++. <abc value="xyz "pqr""/> how do I parse this attribute? I tried using void startElementNsSAX2Func(void * ctx, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI, int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, const xmlChar ** attributes) , incrementing attributes parameter( and checking for a " to indicate the end of the attribute value). It works for all the