Android documentbuilderfactory setvalidating

14-Jan-2016 21:07

Is there another parser that implements XML-validation or that is capable to ignore whitespaces?

@Override public Document Builder new Document Builder() throws Parser Configuration Exception { if (is Validating()) { throw new Parser Configuration Exception( "No validating Document Builder implementation available"); } /** * TODO If Android is going to support a different Document Builder * implementations, this should be wired here.

Copyright © 1993, 2016, Oracle and/or its affiliates.

An example from one of my projects: public Document parse XML(Input Source source) { try { Document Builder Factory dbf = Document Builder Instance(); Namespace Aware(false); Validating(false); Document Builder db = Document Builder(); return db.parse(source); } catch (Exception e) { e.print Stack Trace(); return null; } } To start with use DOM parser. If you must move to SAX, first measure your response times when using DOM, and only if parsing is causing you the most pain, then move to SAX.

*/ @Override public void on Create(Bundle saved Instance State) { Create(saved Instance State); set Content View(R.layout.main); Button btn = (Button) find View By Id(button1); On Click Listener(new On Click Listener() { @Override public void on Click(View v) { // Load XML for parsing.If we wanted to * allow different implementations, these could be distinguished by * a special feature (like * or by throwing the full SPI monty at it. My first option is Document Builder since do not create an API version restriction (is available since API Level 1). People will argue that SAX is faster, yes it is, but DOM is easier, lesser code and lesser bugs. = -1) { output Stream.write(buf, 0, len); } output Stream.close(); input Stream.close(); } catch (IOException e) { } return output String(); } } There is several ways to read a XML in Android.

The reason I need validation for is to ignore whitespaces in the XML file (blanks, carriage returns, line feeds, etc.).

Thats how I want to parse the document: Document Builder Factory dbfac = Document Builder Instance(); Validating(true); Ignoring Element Content Whitespace(true); Document Builder doc Builder; doc Builder = Document Builder(); Document d = doc Builder.parse(file); I just found a post on google-code that indicates that XML validation is not implemented: link This post is 1,5 years old and I don't know if something has changed already.