stax

When should I choose SAX over StAX?

谁说我不能喝 提交于 2019-11-27 16:54:28
Streaming xml-parsers like SAX and StAX are faster and more memory efficient than parsers building a tree-structure like DOM-parsers. SAX is a push parser, meaning that it's an instance of the observer pattern (also called listener pattern). SAX was there first, but then came StAX - a pull parser, meaning that it basically works like an iterator. You can find reasons why to prefer StAX over SAX everywhere, but it usually boils down to: "it's easier to use". In the Java tutorial on JAXP StAX is vaguely presented as the middle between DOM and SAX: "it's easier than SAX and more efficient than

why is sax parsing faster than dom parsing ? and how does stax work?

陌路散爱 提交于 2019-11-27 12:30:46
somewhat related to: libxml2 from java yes, this question is rather long-winded - sorry. I kept is as dense as I felt possible. I bolded the questions to make it easier to peek at before reading the whole thing. Why is sax parsing faster than dom parsing? The only thing I can come up with is that w/ sax you're probably ignoring the majority of the incoming data, and thus not wasting time processing parts of the xml you don't care about. IOW - after parsing w/ SAX, you can't recreate the original input. If you wrote your SAX parser so that it accounted for each and every xml node (and could

How to satisfy dependencies for Apache POI on Android?

无人久伴 提交于 2019-11-27 08:04:06
问题 There are many posts about reading .docx files with Apache POI on Android. I write Java program, which do it and want move it Android platform. But XWPFDocument requires xmlbeans.jar, and xmlbeans.jar requires stax-api.jar. And Stax API can not be added to android app , because it tries to extends javax.* namespace, which is not allowed. So question is: how can I satisfy dependencies for Apache POI on Android? 回答1: There are now at least two projects which try to solve most of the problems

Why does the STAX parser think this is valid XML 1.0 but not 1.1?

柔情痞子 提交于 2019-11-27 07:04:12
问题 In the following code example, I use the STaX parser to parse a piece of XML. If I run the xml10 through it, it works as expected. The xml11 string (which is the same, except for the xml version) - it throws a NullPointerException. I'm running this on a Mac using JDK 1.6. import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamReader; import java.io.ByteArrayInputStream; import java.io.InputStream;

What are the differences between DOM, SAX and StAX XML parsers? [closed]

£可爱£侵袭症+ 提交于 2019-11-27 05:13:26
I'm developing a RSS feed aggregator with Apache Tomcat. I was wondering which parser to use in order to read RSS feeds. Should I use DOM, SAX or StAX? I know that there are libraries specific to read RSS feeds with java but since this is a university project I am not supposed to use those. Thank you. OldCurmudgeon It mostly depends on your needs. Each has it's own features. DOM - pull the whole thing into memory and walk around inside it. Good for comparatively small chunks of XML that you want to do complex stuff with. XSLT uses DOM. SAX - Walk the XML as it arrives watching for things as

Read XML String using StAX

时光毁灭记忆、已成空白 提交于 2019-11-27 02:48:01
问题 I am using stax for the first time to parse an XML String. I have found some examples but can't get my code to work. This is the latest version of my code: public class AddressResponseParser { private static final String STATUS = "status"; private static final String ADDRESS_ID = "address_id"; private static final String CIVIC_ADDRESS = "civic_address"; String status = null; String addressId = null; String civicAddress = null; public static AddressResponse parseAddressResponse(String response

StAX XML formatting in Java

[亡魂溺海] 提交于 2019-11-27 01:49:34
Is it possible using StAX (specifically woodstox) to format the output xml with newlines and tabs, i.e. in the form: <element1> <element2> someData </element2> </element1> instead of: <element1><element2>someData</element2></element1> If this is not possible in woodstox, is there any other lightweight libs that can do this? Via the JDK: transformer.setOutputProperty(OutputKeys.INDENT, "yes"); . There is com.sun.xml.txw2.output.IndentingXMLStreamWriter XMLOutputFactory xmlof = XMLOutputFactory.newInstance(); XMLStreamWriter writer = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(out))

“Content is not allowed in prolog” when parsing perfectly valid XML on GAE

a 夏天 提交于 2019-11-26 22:17:21
I've been beating my head against this absolutely infuriating bug for the last 48 hours, so I thought I'd finally throw in the towel and try asking here before I throw my laptop out the window. I'm trying to parse the response XML from a call I made to AWS SimpleDB. The response is coming back on the wire just fine; for example, it may look like: <?xml version="1.0" encoding="utf-8"?> <ListDomainsResponse xmlns="http://sdb.amazonaws.com/doc/2009-04-15/"> <ListDomainsResult> <DomainName>Audio</DomainName> <DomainName>Course</DomainName> <DomainName>DocumentContents</DomainName> <DomainName

Is there a Java XML API that can parse a document without resolving character entities?

不羁岁月 提交于 2019-11-26 21:06:50
I have program that needs to parse XML that contains character entities. The program itself doesn't need to have them resolved, and the list of them is large and will change, so I want to avoid explicit support for these entities if I can. Here's a simple example: <?xml version="1.0" encoding="UTF-8"?> <xml>Hello there &something;</xml> Is there a Java XML API that can parse a document successfully without resolving (non-standard) character entities? Ideally it would translate them into a special event or object that could be handled specially, but I'd settle for an option that would silently

stax xml validation

谁说胖子不能爱 提交于 2019-11-26 19:31:45
问题 I know I can validate xml-file when I use sax. But can I validate when I use Stax? 回答1: There are two ways of XML validation possible with SAX and DOM: validate alone - via Validator.validate() validate during parsing - via DocumentBuilderFactory.setSchema() and SAXParserFactory.setSchema() With StAX, validation is possible , but only the first way of doing it. You can try something like this: import javax.xml.validation.*; import javax.xml.transform.stax.*; import javax.xml.stream.*; import