Considérez que j'ai un DOMParser standard, écrit le long des lignes de:Problème analyse syntaxique Chaîne à DOM en Java
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder(); factory.newDocumentBuilder().newDocument();
this.document = builder.parse(new InputSource(new StringReader(xmlString)));
Puis, quand je nourris cela, il fonctionne:
<?xml version="1.0" encoding="utf-8" standalone="no"?><rsp stat="ok">
<photos page="1" pages="385628" perpage="10" total="3856272">
<photo farm="7" id="5943736412" isfamily="0" isfriend="0" ispublic="1" owner="[email protected]" secret="7c3ee3a0ee" server="6144" title="SOOC"/>
<photo farm="7" id="5943736298" isfamily="0" isfriend="0" ispublic="1" owner="[email protected]" secret="3a6d0657e0" server="6130" title="Large Express Orange Cami with Lace Trim $1"/>
<photo farm="7" id="5943180023" isfamily="0" isfriend="0" ispublic="1" owner="[email protected]" secret="36177b9be7" server="6022" title="little fellow at the heart"/>
<photo farm="7" id="5943741338" isfamily="0" isfriend="0" ispublic="1" owner="[email protected]" secret="f5dcb26ba0" server="6025" title="Freeway Drive"/>
<photo farm="7" id="5943182403" isfamily="0" isfriend="0" ispublic="1" owner="[email protected]" secret="1a77e9ea6f" server="6131" title="Mk1_Orange"/>
<photo farm="7" id="5943159235" isfamily="0" isfriend="0" ispublic="1" owner="[email protected]" secret="cd80b51040" server="6027" title="D'CLOSET; GD1181 (97% Rayon 3% Spandex) Navy, Black, Dark Orange ~45.5 in. +55.5 in. $16.25 01-3."/>
<photo farm="7" id="5943150801" isfamily="0" isfriend="0" ispublic="1" owner="[email protected]" secret="d22b924c36" server="6124" title="orange_hat5"/>
<photo farm="7" id="5943149751" isfamily="0" isfriend="0" ispublic="1" owner="[email protected]" secret="45a4d3681f" server="6137" title="Southern White Faced (Scops) Owl (Ptilopsis granti)"/>
<photo farm="7" id="5943147771" isfamily="0" isfriend="0" ispublic="1" owner="[email protected]" secret="b79de60d1a" server="6148" title="Another shot of the orange #VW #Beetle everybody loved so much :)"/>
<photo farm="7" id="5943169451" isfamily="0" isfriend="0" ispublic="1" owner="[email protected]" secret="3137cccc19" server="6128" title="365:26 - False Coloured"/>
</photos>
</rsp>
Mais quand je nourrir cela, il n'analyse pas, et jette l'exception ci-dessous:
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<photos page="1" pages="385871" perpage="10" total="3858702">
<photo id="5943232363" owner="[email protected]" secret="ed3a8c8859" server="6142" farm="7" title="Sunset" ispublic="1" isfriend="0" isfamily="0" />
<photo id="5943241319" owner="[email protected]" secret="3eeefe774d" server="6018" farm="7" title="Sunset" ispublic="1" isfriend="0" isfamily="0" />
<photo id="5943783494" owner="[email protected]" secret="40488c323f" server="6142" farm="7" title="Sunset" ispublic="1" isfriend="0" isfamily="0" />
<photo id="5943788400" owner="[email protected]" secret="a71e479368" server="6003" farm="7" title="Sunset Storm Clouds" ispublic="1" isfriend="0" isfamily="0" />
<photo id="5943238975" owner="[email protected]" secret="eebcee0087" server="6148" farm="7" title="Clouds of Fire" ispublic="1" isfriend="0" isfamily="0" />
<photo id="5943240733" owner="[email protected]" secret="13b8236166" server="6024" farm="7" title="Clouds of Fire" ispublic="1" isfriend="0" isfamily="0" />
<photo id="5943233445" owner="[email protected]" secret="9ab47a506e" server="6001" farm="7" title="Sunset Storm Clouds" ispublic="1" isfriend="0" isfamily="0" />
<photo id="4866746451" owner="[email protected]" secret="4527be5fcd" server="4121" farm="5" title="alive" ispublic="1" isfriend="0" isfamily="0" />
<photo id="5943234465" owner="[email protected]" secret="600d8af8ee" server="6141" farm="7" title="Sunset Storm Clouds" ispublic="1" isfriend="0" isfamily="0" />
<photo id="5943243347" owner="[email protected]" secret="de74666e23" server="6029" farm="7" title="Moon" ispublic="1" isfriend="0" isfamily="0" />
</photos>
</rsp>
l'exception est jeté:
[Fatal Error] :-1:-1: Premature end of file.
Exception in thread "main" org.xml.sax.SAXParseException: Premature end of file.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
Toutes les idées seraient très appréciées!
Comment la variable xmlString est-elle remplie? – Brabster
Le premier que je charge à partir d'un fichier. Transformer en une chaîne, appelons-la 'xmlString1'. Ensuite, essayez de ré-analyser. La seconde est obtenue en faisant un appel RESTful à un api. – Larry