0

I've tried all different kind of combinations but I just don't get what it wants from me:

java.net.MalformedURLException: no protocol: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ds><ds>...
    at java.net.URL.<init>(URL.java:593)
    at java.net.URL.<init>(URL.java:490)
    at java.net.URL.<init>(URL.java:439)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:620)
    at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:148)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:805)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:177)

I've looked at other questions but I don't get what is wrong with my XML.

This is the full XML (with some plain text removed):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ds>
    <ds>
        <cue>ABGB : §§ 786 , 810 , 812 </cue>Die Kosten ... <cue>Anmerkung : </cue>
        ... <cue>Bestätigung von </cue>7 
        <Relation bewertung="1">Ob 56/10a </Relation>= Zak 
        <Relation bewertung="1">2010/773 , 440 </Relation>. 
    </ds>
</ds>

The producing code:

DocumentBuilderFactory icFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder icBuilder;

Document parse = null;

try {
    icBuilder = icFactory.newDocumentBuilder();             
    parse = icBuilder.parse(xmlString);
} catch (ParserConfigurationException e) {
    e.printStackTrace();
} catch (SAXException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378

2 Answers2

7

The parse(String) method takes a uri pointing to an XML document, not its content.

In order to parse the content, you'll have to construct your own InputSource. E.g.:

parse = icBuilder.parse(new InputSource(new StringReader(xmlString)));
Mureinik
  • 297,002
  • 52
  • 306
  • 350
5

You're passing a String to icBuilder.parse(xmlString), so you're actually invoking DocumentBuilder.parse(String uri).

The method expects an URI and will try to parse it as such, while you're passing it some XML data.

Aaron
  • 24,009
  • 2
  • 33
  • 57