stax

How to read modify fragments of XML using StAX in Java?

限于喜欢 提交于 2019-12-11 01:44:00
问题 My goal is to read objects (featureMember) into DOM, change them and write back into new XML. XML is too big to use DOM itself. I figured what I need is StAX and TransformerFactory, but I can't make it work. This is what I've done till now: private void change(File pathIn, File pathOut) { try { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLOutputFactory factoryOut = XMLOutputFactory.newInstance(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf

Omitting XML Declaration when invoking Transformer with StAXResult

自作多情 提交于 2019-12-10 23:49:20
问题 I would like to copy multiple XML nodes from a source XML file to a target file. Both source and target files are very large, so I will use StAX. Typically the file I'm trying to process looks as follows: <root> <header> <title>A List of persons</title> </header> <person> <name>Joe</name> <surname>Bloggs</surname> </person> <person> <name>John</name> <surname>Doe</surname> </person> . . etc... </root> The target files should be in the following format: <root> <header> <title>A List of persons

JAVA: gathering byte offsets of xml tags using an XmlStreamReader

限于喜欢 提交于 2019-12-10 17:54:39
问题 Is there a way to accurately gather the byte offsets of xml tags using the XMLStreamReader? I have a large xml file that I require random access to. Rather than writing the whole thing to a database, I would like to run through it once with an XMLStreamReader to gather the byte offsets of significant tags, and then be able to use a RandomAccessFile to retrieve the tag content later. XMLStreamReader doesn't seem to have a way to track character offsets. Instead people recommend attaching the

StAX - how to set XMLInputFactory.IS_VALIDATING to true?

偶尔善良 提交于 2019-12-10 14:51:06
问题 this is my first time using StAX for parsing XML documents (still in the learning stage). During the process to parse an XML document using XMLStreamReader and generate a copy of the document using XMLStreamWriter, I encountered the following warning represented as a comment in the output of the writer: <!-- Exception scanning External DTD Subset. True contents of DTD cannot be determined. Processing will continue as XMLInputFactory.IS_VALIDATING == false. --> I understood the cause of the

Why does StAX create XML slower than DOM?

℡╲_俬逩灬. 提交于 2019-12-10 11:19:17
问题 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

Android StAX Cursor Parser - could not find method javax.xml.stream.XMLInputFactory.newInstance

冷暖自知 提交于 2019-12-10 11:16:11
问题 I'm using AsyncTask to download and parse XML content from i-net. Downloading and parsing of the xml happens in doInBackground() method. The "dalvikvm" encounters a problem - it could not find a method. Here is the log of LogCat: 06-30 13:26:41.148: DEBUG/dalvikvm(507): GC freed 796 objects / 68088 bytes in 112ms 06-30 13:26:41.667: INFO/ActivityManager(52): Displayed activity com.news.reader/.SplashScreen: 5305 ms (total 63417 ms) 06-30 13:26:45.097: INFO/ActivityManager(52): Starting

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

Parsing multiple XML fragments with STaX

会有一股神秘感。 提交于 2019-12-10 10:13:53
问题 I was hoping the following would be parseable in StAX, <something a="b"/> <something a="b"/> But it chokes when you reach the second element. As there is no common root element. (I'm not too sure why a pull parser cares about this particular issue... anyway...) I can fake a root element, e.g. Guava: InputSupplier<Reader> join = CharStreams.join( newReaderSupplier("<root>"), newReaderSupplier(new File("...")), newReaderSupplier("</root>")); XMLInputFactory xif = XMLInputFactory.newInstance();

StAX XML all content between two required tags

可紊 提交于 2019-12-10 03:34:19
问题 Starting learning the StAX, using XMLStreamReader, I faced with some problem. How can I get ALL content between tags as Text? I mean, I know name of needed tag, and when I find it, I must go to the close tag, and everything I found between them I must append at some string. For example, we have something like <rootTag> ... <someTag> Some text content and other tags here… </someTag > <tagINeed> <someinternalTag1> <someinternalTag11> Some text content.. </someinternalTag11> ... <

Best StAX Implementation [closed]

假装没事ソ 提交于 2019-12-08 23:07:47
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . My quick search reveals the reference implementation (http://stax.codehaus.org), the Woodstox implementation (http://woodstox.codehaus