Issue 41 in xmltool: Handling the "Content not allowed in prolog" message

1 view
Skip to first unread message

xml...@googlecode.com

unread,
Jul 24, 2012, 2:55:21 PM7/24/12
to xml...@googlegroups.com
Status: New
Owner: ----

New issue 41 by auste...@gmail.com: Handling the "Content not allowed in
prolog" message
http://code.google.com/p/xmltool/issues/detail?id=41

When loading a improperly encoded XML file that IS properly formatted XML (
in my case a UTF-8 file), sometimes the XMLDoc.from() method throws
the "Content not allowed in prolog" message and I am dead in the water and
can no longer use your tool to load the file. In that case I have to write
my own 15 lines of code to manually load the file otherwise.

Is it possible you can provide some functionality to help users of your
tool get around this message?

xml...@googlecode.com

unread,
Jul 24, 2012, 3:34:02 PM7/24/12
to xml...@googlegroups.com

Comment #1 on issue 41 by auste...@gmail.com: Handling the "Content not
This was my workaround. I wish I didn't have to do this but since xmltool
couldn't read the file , I was required to do this :

public String getValByXpath( String xpathstr ) {
// can't use XMLDoc here because XmlInvoiceClient stores invalidly
encoded xml
// so, I do this all manually below just to get the Assert
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
XPathExpression xp;
Document doc;
String success = null;
try {
builder = factory.newDocumentBuilder();
doc = builder.parse( "result.xml" );
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
xp = xpath.compile( xpathstr );
success = xp.evaluate( doc );
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XPathExpressionException e) {
e.printStackTrace();
}
return success;
}



xml...@googlecode.com

unread,
Jul 27, 2012, 12:20:56 PM7/27/12
to xml...@googlegroups.com

Comment #2 on issue 41 by auste...@gmail.com: Handling the "Content not
So, I decided to abandon xmltool in favor of these 2 xml classes I created,
which have no problems with reading XML BOM from any file encoding :
http://thegreenoak.blogspot.com/2012/07/writing-string-value-to-xml-file-using.html

xml...@googlecode.com

unread,
Dec 17, 2012, 5:40:08 PM12/17/12
to xml...@googlegroups.com

Comment #3 on issue 41 by mathieu....@gmail.com: Handling the "Content not
Are you sure the error message is really from XMLTool and not from the Java
XML API ? I already had this message: it triggers when your XML is invalid.
Usually when you have a special unreadable character at the beginning of
the file.

Perhaps because if the input stream of platform encoding ?


xml...@googlecode.com

unread,
Dec 17, 2012, 9:33:40 PM12/17/12
to xml...@googlegroups.com

Comment #4 on issue 41 by auste...@gmail.com: Handling the "Content not
Yes, I am sure. I provided a code snippet in my July 27th comment that
shows that a pure Java XML API works. Sorry, I didn't provide an example
file but if you created unit tests with the variations you can think of,
you would probably find it, IMHO.

Reply all
Reply to author
Forward
0 new messages