sax

SAX parsing: how to fetch child nodes

自古美人都是妖i 提交于 2019-12-07 08:17:03
问题 I'm using SAX parsing in android. For below XML: <?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> <channel> <title>Game Analysis</title> <item> <title>GTA</title> <description>ABC</description> <pubDate>Sat, 21 Feb 2012 05:18:23 GMT</pubDate> <enclosure type="audio/mpeg" url="http://URL.mp3" length="6670315"/> </item> <item> <title>CoD</title> <description>XYZ</description> <pubDate>Sat, 21 Feb 2011 05:18:23 GMT</pubDate> <enclosure type="audio/mpeg" url="http://URL.mp3" length=

How to parse different XML files using SAX on Android?

血红的双手。 提交于 2019-12-07 07:49:28
I have the following scenario. I send a XML file to a server as a request and get a XML file as response and all that as a background thread on Android. The XML request is serialized using various values. The XML response is then read by SAX and put into a list. The whole request/response process happens in a background thread using the AsyncTask class. The problem is that I have different types of responses and I have no idea what approach to take to parse the response based on the request sent. How do I tell Android to use parser A based on request A and parser B based on request B? EDIT:

How to stream XML output quickly from Python

感情迁移 提交于 2019-12-07 04:56:43
问题 What is a quick way of writing an XML file iteratively (i.e. without having the whole document in memory)? xml.sax.saxutils.XMLGenerator works but is slow, around 1MB/s on an I7 machine. Here is a test case. 回答1: I realize that this question has been asked awhile ago, but, in the mean time, an lxml API has been introduced that looks promising in terms of addressing the problem: http://lxml.de/api.html ; specifically, refer to the following section: "Incremental XML generation". I quickly

How can I process xml asynchronously in python?

*爱你&永不变心* 提交于 2019-12-07 03:06:25
问题 I have a large XML data file (>160M) to process, and it seems like SAX/expat/pulldom parsing is the way to go. I'd like to have a thread that sifts through the nodes and pushes nodes to be processed onto a queue, and then other worker threads pull the next available node off the queue and process it. I have the following (it should have locks, I know - it will, later) import sys, time import xml.parsers.expat import threading q = [] def start_handler(name, attrs): q.append(name) def do_expat(

Using SAX (Java) to parse multiple XML messages from a single TCP-stream

谁说胖子不能爱 提交于 2019-12-07 02:01:09
问题 I'm in a position where I use Java to connect to a TCP port and am streamed XML documents one after another, each delimited with the <?xml start of document tag. An example which demonstrates the format: <?xml version="1.0"?> <person> <name>Fred Bloggs</name> </person> <?xml version="1.0"?> <person> <name>Peter Jones</name> </person> I'm using the org.xml.sax.* api. The SAX parsing works perfectly for the first document but throws an exception when it comes across the start of the second

Java: Saving StreamResult to a file

亡梦爱人 提交于 2019-12-06 18:24:32
问题 I am doing some data conversion(like csv) to xml with SAX then using transformer in Java. The result is in StreamResult, and I am trying to save this result to a file.xml but I can't find way to save StreamResult into file. am I doing this all wrong? 回答1: Your StreamResult should be created on the basis of a file, e.g. StreamResult sr = new StreamResult(new File("/my/file.xml")); If you give your Transformer such a StreamResult , it will write its result directly into the file you specified.

How should I strip invalid XML characters from a stream in J2ME? org.xml.sax.SAXParseException: Invalid character

自古美人都是妖i 提交于 2019-12-06 14:21:56
问题 This code is running on Blackberry JDE v4.2.1 It's in a method that makes web API calls that return XML. Sometimes, the XML returned is not well formed and I need to strip out any invalid characters prior to parse. Currently, I get: org.xml.sax.SAXParseException: Invalid character '' encountered . I would like to see ideas of a fast way to attach an invalid character stripper on the input stream so that the stream just flows through the validator/stripper and into the parse call. i.e. I'm

Parsing an XML SAX way in R

这一生的挚爱 提交于 2019-12-06 13:52:13
问题 Originating from this question, my research of R (and other) documentation indicates that SAX approach will be a faster way to parse XML data. Sadly I couldn't find much working examples for me to understand how to get there. Here's a dummy file with information that I want parsed. The real thing would have substantially more <ITEM> nodes and other nodes all around the tree that I would like to exclude. Another peculiarity is that the <META> section has two <DESC> elements, and I need any one

SAX Parser and XML Schema (XSD) validation

若如初见. 提交于 2019-12-06 13:31:16
问题 Which Java XML libraries can do SAX-based parsing and validation against an XML Schema (XSD) at the same time? I'm really looking for the most efficient solution for reading and validating large XML files. bonus points if you can provide sample code. 回答1: Xerces which is part of the Sun JDK can do validation. You can see in the docs. 回答2: As suggested by Robert , Xerces provides SAX-based parsing and XSD validation. You can checkout example at : http://www.herongyang.com/XML-Schema/Xerces2

Android : Cdata in xml not parsing correctly(sax)

夙愿已清 提交于 2019-12-06 13:27:43
I'm new to android development, and im trying to create an app that is pulling xml from a web service. all the rest of the xml pulls in fine, apart from the bits in the Cdata tag, instead of pulling in a large ammount of html text, it pulls in " <p> ". Could someone point me in the right direction as to why its not pulling in properly here is my xml <articles> <article> <name>AndroidPeople</name> <headline>notandroidpeople</headline> <website category="android">www.androidpeople.com</website> <htmltext><![CDATA[<p> HAVING lost to Manchester City and drawn with Manchester United, Yohan Cabaye