stax

Is there a way to build a StAX filter chain?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 02:35:18
问题 Making custom transformations for different event types with StAX using EventFilter and StreamFilter I feel being forced into a procedural implementation - extract these events and process them, filter those events and process them, than put all the results back together and return. SAX seems to have a really nice feature there - chainable filters based on XMLFilters. I would prefer to keep my implementation StAX-based, but to somehow incorporate or emulate the chainable filters from SAX. Can

How to modify a huge XML file by StAX?

浪子不回头ぞ 提交于 2019-12-18 11:34:48
问题 I have a huge XML (~2GB) and I need to add new Elements and modify the old ones. For example, I have: <books> <book>....</book> ... <book>....</book> </books> And want to get: <books> <book> <index></index> .... </book> ... <book> <index></index> .... </book> </books> I used the following code: XMLInputFactory inFactory = XMLInputFactory.newInstance(); XMLEventReader eventReader = inFactory.createXMLEventReader(new FileInputStream(file)); XMLOutputFactory factory = XMLOutputFactory

How to modify a huge XML file by StAX?

落花浮王杯 提交于 2019-12-18 11:33:59
问题 I have a huge XML (~2GB) and I need to add new Elements and modify the old ones. For example, I have: <books> <book>....</book> ... <book>....</book> </books> And want to get: <books> <book> <index></index> .... </book> ... <book> <index></index> .... </book> </books> I used the following code: XMLInputFactory inFactory = XMLInputFactory.newInstance(); XMLEventReader eventReader = inFactory.createXMLEventReader(new FileInputStream(file)); XMLOutputFactory factory = XMLOutputFactory

how to override a service provider in java

半世苍凉 提交于 2019-12-18 05:50:35
问题 This is more a general question by example: I'm using xstream and woodstox, woodstox comes with a service provider for javax.xml.stream.XMLOutputFactory in woodstox jar registering com.ctc.wstx.stax.WstxOutputFactory. I want to provide my own javax.xml.stream.XMLOutputFactory and still have woodstox jar in the classpath. I know I can provide my own with the system property javax.xml.stream.XMLOutputFactory , but I'm trying to take off the hassle from our dev ops team and do it with a service

Formatting XML file using StAX

梦想与她 提交于 2019-12-17 19:26:09
问题 I am using StAX XML stream writer to write the XML file. It writes all the data in a single line. I want all the tags to be indented instead of a single line. 回答1: stax-utils provides class IndentingXMLStreamWriter which does the job: XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(...); writer = new IndentingXMLStreamWriter(writer); ... 回答2: Answered here: StAX XML formatting in Java EDIT: A quick example (without resource cleaning) using stax-utils (https:/

Convert XML file to CSV in java

大城市里の小女人 提交于 2019-12-17 15:36:55
问题 @Before There will be probably some duplicate questions suggestions, I don't think that is the case maybe read this first, I'll try to be as brief as possible. Title gives basic idea. Here is an example XML(case 1) : <root> <Item> <ItemID>4504216603</ItemID> <ListingDetails> <StartTime>10:00:10.000Z</StartTime> <EndTime>10:00:30.000Z</EndTime> <ViewItemURL>http://url</ViewItemURL> .... </item> Here is an example XML(case 2) : <Item> <ItemID>4504216604</ItemID> <ListingDetails> <StartTime>10

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

允我心安 提交于 2019-12-17 10:42:33
问题 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

getCharacterOffset() returns incorrect value

情到浓时终转凉″ 提交于 2019-12-13 17:08:24
问题 I'm using StAX to parse an XML file and would like to know where each tag starts and ends. For that I'm trying to use getLocation().getCharacterOffset() , but it returns incorrect values for every tag beyond first. XMLInputFactory factory = XMLInputFactory.newInstance(); XMLEventReader reader = factory.createXMLEventReader( new StringReader("<root>txt1<tag>txt2</tag></root>")); XMLEvent e; e = reader.nextEvent(); // START_DOCUMENT System.out.println(e); System.out.println(e.getLocation()); e

XMLStreamReader: get character offset : XML from file

余生长醉 提交于 2019-12-13 14:25:26
问题 The XMLStreamReader ->Location has a method called getCharacterOffset() . Unfortunately the Javadocs indicate this is an ambigously named method: it can also return a byte-offset (and this appears to be true in practice); unhelpfully this seems to occur when reading from files (for instance): The Javadoc states : Return the byte or character offset into the input source this location is pointing to. If the input source is a file or a byte stream then this is the byte offset into that stream,

Parsing XML with no closing tags in Java

故事扮演 提交于 2019-12-13 08:27:49
问题 I am having trouble parsing an XML with no closing tag. Please see snippet of the xml below. I have tried SAX and also StAX Parser they both need a properly formatted XML with closing tag XXYY....as you can see below the XML format is a little bit different... Please help me if there is any API out there that can help me parse this or if SAX/StAX can help me achieve what I want.... :( <Employees> <Employee> <Detail> <Date>2018014 <Name>XXYY <Age>0 <LANGUAGE>ENG <Manager> <MName>YYXX <MID>5959