stax

Parse XML using Java StAX - Count number of content tags

核能气质少年 提交于 2019-12-08 06:41:06
问题 I have big XML file and I am parsing as below: public class Solution { private static final String ROOM_ID = "RoomID"; private static final String CONTENT = "Content"; private static final String LOGIN_NAME = "LoginName"; private static final String CONVERSATION_ID = "ConversationID"; private static final String FILE_DUMP = "FileDump"; private static final String MESSAGE = "Message"; private static final String CONVERSATION = "Conversation"; private static final String START_TIME = "StartTime

Cannot convert value of type 'org.springframework.batch.item.xml.StaxEventItemWriter' to required type 'org.springframework.batch.item.ItemReader'

依然范特西╮ 提交于 2019-12-08 05:43:59
问题 I am developing Spring Batch MongoDB to XML example. I've successfully created the project, but when I am running it I see the below error is coming, I don't know what is going wrong here. Error for reference Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org

How to get the value of a specific XML tag using StaX [duplicate]

瘦欲@ 提交于 2019-12-08 01:54:47
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: How to use StaX Hey guys so I have an XML file and I want Java to spit out the value of a specific tag. For example here is my XML: <?xml version="1.0"?> <dennis> <hair>brown</hair> <pants>blue</pants> <gender>male</gender> </dennis> So let's say I want Java to spit out the value of "gender" is there code I could use like XMLStreamReader.goToTag("gender"); System.out.println(XMLStreamReader.getLocalName());

Java, XMLEvent location Characters

孤街浪徒 提交于 2019-12-08 01:28:16
问题 I'm parsing the following String with a StAX XMLEventReader: final String xmlstr = "<context><book><author>TheName</author></book></context>"; I'm observing the event.getLocation().getCharacterOffset() value and get some weird behavior: While the index for START_ELEMENT is reported at the position after the element declaration (e.g. index 9 for the context element), the CHARACTERS event for "TheName" is reported to be on index 32. Why? Is there a way to correct that? 回答1: I encountered a

Cannot convert value of type 'org.springframework.batch.item.xml.StaxEventItemWriter' to required type 'org.springframework.batch.item.ItemReader'

一曲冷凌霜 提交于 2019-12-07 01:18:27
I am developing Spring Batch MongoDB to XML example. I've successfully created the project, but when I am running it I see the below error is coming, I don't know what is going wrong here. Error for reference Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.batch.item.xml.StaxEventItemWriter' to required type 'org.springframework.batch.item.ItemReader'

Why does StAX create XML slower than DOM?

我的未来我决定 提交于 2019-12-06 14:26:41
i was trying to measure time needed for StAX and DOM to create two same documents. I dont know why DOM is faster in creating XML. Maybe my code for StAX writer is not very good. so here it is StAX(longer code) public static final int pocet =100000; try { String encoding = "UTF-8"; XMLOutputFactory f = XMLOutputFactory.newInstance(); XMLStreamWriter w = f.createXMLStreamWriter( new FileOutputStream(subor), encoding); w.writeStartDocument(encoding, "1.0"); w.writeCharacters("\r\n"); w.writeStartElement("Noviny"); for (int i = 1; i <= pocet; i++) { w.writeCharacters("\r\n "); w.writeStartElement(

How to get the value of a specific XML tag using StaX [duplicate]

妖精的绣舞 提交于 2019-12-06 14:25:22
This question already has an answer here : Closed 7 years ago . Possible Duplicate: How to use StaX Hey guys so I have an XML file and I want Java to spit out the value of a specific tag. For example here is my XML: <?xml version="1.0"?> <dennis> <hair>brown</hair> <pants>blue</pants> <gender>male</gender> </dennis> So let's say I want Java to spit out the value of "gender" is there code I could use like XMLStreamReader.goToTag("gender"); System.out.println(XMLStreamReader.getLocalName()); You could do the following: StreamSource xml = new StreamSource("input.xml"); XMLStreamReader xsr = xif

Java, XMLEvent location Characters

两盒软妹~` 提交于 2019-12-06 08:15:40
I'm parsing the following String with a StAX XMLEventReader: final String xmlstr = "<context><book><author>TheName</author></book></context>"; I'm observing the event.getLocation().getCharacterOffset() value and get some weird behavior: While the index for START_ELEMENT is reported at the position after the element declaration (e.g. index 9 for the context element), the CHARACTERS event for "TheName" is reported to be on index 32. Why? Is there a way to correct that? Dan Halbert I encountered a similar problem when going from the latest jdk6 to the latest jdk7. There seems to be a bug in com

StAX - reading base64 string from xml into db

二次信任 提交于 2019-12-06 07:42:04
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(XMLInputFactory.IS_COALESCING, Boolean.FALSE); xmlif.configureForLowMemUsage(); List<Entity> entities = new

How do I keep track of parsing progress of large files in StAX?

谁说胖子不能爱 提交于 2019-12-06 07:25:10
I'm processing large (1TB) XML files using the StAX API. Let's assume we have a loop handling some elements: XMLInputFactory fac = XMLInputFactory.newInstance(); XMLStreamReader reader = fac.createXMLStreamReader(new FileReader(inputFile)); while (true) { if (reader.nextTag() == XMLStreamConstants.START_ELEMENT){ // handle contents } } How do I keep track of overall progress within the large XML file? Fetching the offset from reader works fine for smaller files: int offset = reader.getLocation().getCharacterOffset(); but being an Integer offset, it'll probably only work for files up to 2GB...