sax

Trouble parsing self closing XML tags using SAX parser

℡╲_俬逩灬. 提交于 2019-12-04 04:37:19
问题 I am having trouble parsing self closing XML tags using SAX. I am trying to extract the link tag from the Google Base API.I am having reasonable success in parsing regular tags. Here is a snippet of the xml <entry> <id>http://www.google.com/base/feeds/snippets/15802191394735287303</id> <published>2010-04-05T11:00:00.000Z</published> <updated>2010-04-24T19:00:07.000Z</updated> <category scheme='http://base.google.com/categories/itemtypes' term='Products'/> <title type='text'>En-el1 Li-ion

Insert new element to an XML file using SAX Filter

别等时光非礼了梦想. 提交于 2019-12-04 04:11:37
问题 I have an XMl file that looks like: <?xml version="1.0" encoding="UTF-8"?> <game > <moves> <turn>2</turn> <piece nr="1" /> <turn>4</turn> <piece nr="1" /> </moves> </game> I am writing a Java program that takes the XML file as input then parses it with SAX and SAX filter and computes: the sum of the content of turn element (here=6) the number of piece elements (here=2) Then I want to use a SAX filter in order to generate an output XML file that are the same as the input one but with an

The markup must be well-formed

杀马特。学长 韩版系。学妹 提交于 2019-12-04 03:21:35
First off, let me say I am a new to SAX and Java. I am trying to read information from an XML file that is not well formed. When I try to use the SAX or DOM Parser I get the following error in response: The markup in the document following the root element must be well-formed. This is how I set up my XML file: <format type="filename" t="13241">0;W650;004;AG-Erzgeb</format> <format type="driver" t="123412">001;023</format> ... Can I force the SAX or DOM to parse XML files even if they are not well formed XML? Thank you for your help. Much appreciated. Haythem Your best bet is to make the XML

Parse a list of XML fragments with no root element from a stream input

倖福魔咒の 提交于 2019-12-04 02:48:56
Is it feasible in Java using the SAX api to parse a list of XML fragments with no root element from a stream input? I tried parsing such an XML but got a org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed. before even the endDocument event was fired. I would like not to settle with obvious but clumsy solutions as "Pre-append a custom root element or Use buffered fragment parsing". I am using the standard SAX API of Java 1.6. The SAX factory had setValidating(false) in case anyone wondered. npe First, and most important of all, the content

Referring to a local DTD in Java

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 02:35:41
I have some XML that I'm parsing with a SAX parser in Java. It starts with this preamble: <!DOCTYPE math PUBLIC "-//W3C//DTD MathML 3.0//EN" "http://www.w3.org/Math/DTD/mathml3/mathml3.dtd"> How do I change this to use a local DTD? I suppose I could do something like this: <!DOCTYPE math PUBLIC "-//W3C//DTD MathML 3.0//EN" "file:///c:/MathML/mathml3.dtd"> Not exactly like that, but something like that. However, I need the path to be independent of the user's system. How do I use a local DTD with a path relative to the class path? Take a look at this article on using XML catalogs to resolve

Unable to parse value containing special character? Using sax parser

风格不统一 提交于 2019-12-04 01:38:28
问题 I am new to parsing field. I'm trying to write a parser code but unable to get the value with respect to a particular tag that value contains ampersand(&) . Please help me to get the solution. My xml file looks like <system> <u_id>10145</u_id> <serial_no>1800015</serial_no> <branch_name>B & P Infotech Ltd.</branch_name> </system> and I have tried with this java code, but it's not giving me proper output. main class package com.satya.xmltest; import javax.xml.parsers.SAXParser; import javax

How to tell Java SAX Parser to ignore invalid character references?

时光怂恿深爱的人放手 提交于 2019-12-03 22:46:15
When trying to parse incorrect XML with a character reference such as &#x1 , Java's SAX Parser dies a horrible death with a fatal error such as org.xml.sax.SAXParseException: Character reference "&#x1" is an invalid XML character. Is there any way around this? Will I have to clean up the XML file before I hand it off to the SAX Parser? If so, is there an elegant way of going about this? Use XML 1.1! skaffman is completely right, but you can just stick <?xml version="1.1"?> on the top of your files and you'll be in good shape. If you're dealing with streams, write a wrapper that rewrites or

Java SAXParser - keep InputStream open

試著忘記壹切 提交于 2019-12-03 21:21:23
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. How about something like: class WontCloseBufferedInputStream extends BufferedInputStream { public void close () { // Do nothing. } public void reallyClose() { super.close (); } } You can pass InputSource object rather than InputStream object to SAXParser sample code SAXParser parser = //

XML Validation in Java: processContents=“lax” seems not to work correctly

大兔子大兔子 提交于 2019-12-03 15:12:31
I have an XML Schema which contains a number of <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> definitions, i.e., it allows to insert arbitrary tags of other namespaces. processContents="lax" indicates that the parser should try do validate these tags, if it has the according schema (1) (2) . For me this means, that if I give the parser all schema documents, and there is an invalid XML tag of one of the secondary namespaces, it needs to report an error. However, it seems that the Java XML validator ignores such errors. I have verified that the parser has

A lightweight XML parser efficient for large files?

人盡茶涼 提交于 2019-12-03 12:46:26
I need to parse potentially huge XML files, so I guess this rules out DOM parsers. Is out there any good lightweight SAX parser for C++, comparable with TinyXML on footprint? The structure of XML is very simple, no advanced things like namespaces and DTDs are needed. Just elements, attributes and cdata. I know about Xerces, but its sheer size of over 50mb gives me shivers. Thanks! If you are using C, then you can use LibXML from the Gnome project. You can choose from DOM and SAX interfaces to your document, plus lots of additional features that have been developed over years. If you really