sax

Disable XML Entity resolving in JDOM / DOM

不羁的心 提交于 2019-12-21 17:28:05
问题 I am writing a Java application for the postprocessing of XML files. These xml files come from an RDF-Export of a Semantic Mediawiki, so they have rdf/xml syntax. My problem is the following: When I read the xml file, all the entities in the file get resolved to their value which is specified in the Doctype. For example in the Doctype I have <!DOCTYPE rdf:RDF[ <!ENTITY wiki 'http://example.org/smartgrid/index.php/Special:URIResolver/'> .. ]> and in the root element <rdf:RDF xmlns:wiki="&wiki;

Java SAXParser - keep InputStream open

隐身守侯 提交于 2019-12-21 06:21:58
问题 I've a BufferedInputStream from which I want to parse XML with SAXParser but then reuse it again (eg. mark(int) & reset() ). However this stream is closed in parse() method. Is it possible to somehow tell SAXParser to leave it open? The last resort is to wrap this stream with un-closeable stream. Thank you. 回答1: How about something like: class WontCloseBufferedInputStream extends BufferedInputStream { public void close () { // Do nothing. } public void reallyClose() { super.close (); } } 回答2:

parsing large xml 500M with node.js

妖精的绣舞 提交于 2019-12-20 11:35:16
问题 I am using isaacs' SAX to parse a huge xml file. Also recommended by La Gentz. The process uses about 650M of memory, how can I reduce this or allow node to use even more. FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory My XML file is larger than 300M it could grow to 1GB. 回答1: You should stream the file into the parser, that's the whole point of a streaming parser after all. var parser = require('sax').createStream(strict, options); fs.createReadStream(file).pipe

Turn off validation for a SAXParserFactory

我的梦境 提交于 2019-12-20 06:56:27
问题 On a java application using XML, some tests must be performed with the XML validation disabled in order to ensure that the java parts behave correctly if they face incorrect data. We also need it in order to check older methods (written more than 10 years ago). I tried to locate every occurrence of a SAXParserFactory and use setValidation(false); on it, in order to disable the validation. Unfortunately, I keep getting errors like the one linked below. I have been playing around with this for

sax parser stringbuilder only returning one line [duplicate]

风格不统一 提交于 2019-12-20 05:22:21
问题 This question already has an answer here : Java Sax Parser only returning one line of a tag (1 answer) Closed 6 years ago . I've tried using a StringBuilder named object, but I'm still not getting all the CDATA from the description tag.The xml is located at Events-Ovations365: Basically it only gets the CDATA on one line: img is :http://www.ovations365.com/sites/ovations365.com/images/org/81/newtown_medium.jpg alt="Ocmulgee Heritage Trail Ribbon Cutting"> package com.example.ovations_proj;

Preserve newlines when parsing xml

本秂侑毒 提交于 2019-12-20 03:34:06
问题 I'm using the SAX xml parser to parse some xml data which contains newlines. When using Attributes#getValue, the newline data is lost. How can keep the newlines? 回答1: you can use this code when getting the String to parse: public void characters(char ch[], int start, int length) { for(int i=start; i<length; i++) if(!Character.isISOControl(ch[i])) content.append(ch[i]); } 回答2: The solution was to use instead of \n 来源: https://stackoverflow.com/questions/3401111/preserve-newlines-when-parsing

Validating XML with multiple XSDs in Java

你离开我真会死。 提交于 2019-12-20 03:12:36
问题 I want to parse an XML file with Java and validate it in the same step against an XSD schema. An XML file may contain content of several schemas, like this: <outer xmlns="my.outer.namespace" xmlns:x="my.third.namespace"> <foo>hello</foo> <inner xmlns="my.inner.namespace"> <bar x:id="bar">world</bar> </inner> </outer> Given a namespace the corresponding xsd file can be provided, but the used namespaces are unknown before parsing. If a schema defines default values for attributes, I also want

Validating XML with multiple XSDs in Java

好久不见. 提交于 2019-12-20 03:12:15
问题 I want to parse an XML file with Java and validate it in the same step against an XSD schema. An XML file may contain content of several schemas, like this: <outer xmlns="my.outer.namespace" xmlns:x="my.third.namespace"> <foo>hello</foo> <inner xmlns="my.inner.namespace"> <bar x:id="bar">world</bar> </inner> </outer> Given a namespace the corresponding xsd file can be provided, but the used namespaces are unknown before parsing. If a schema defines default values for attributes, I also want

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

Parsing external XML to JSON in Java?

ⅰ亾dé卋堺 提交于 2019-12-20 01:52:11
问题 So I'm sitting here with Google Geocoder, which returns an XML via 'GOOGLE_URL/xml?address=input&sensor=false'. I need to fetch it by using Java and parse it into a JSON object and send it onwards. How would I go about to do this? (No this is not homework) Note that it should preferably be done within the standard libraries. At the moment I'm trying to work out if it can be done with for example SAX. 回答1: Here is a working example which shows how to connect to a URL, download XML and convert