Fehler beim Parsen der XML-Datei mit StAx

Schrieb ich einen xml-parser mit StAx, das ich zur Analyse von XML-streams vom server empfangen.Hier ist mein code :

private Map<String, IUnitaryAction> parse(InputStream is) throws XMLStreamException {

    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader reader = factory.createXMLStreamReader(is);
    boolean action = false;
    Map<String, IUnitaryAction> actionsMap = new HashMap<String, IUnitaryAction>();

    while(reader.hasNext()){
        int type = reader.next();
        switch(type){
        case XMLStreamReader.START_ELEMENT :
            action = reader.getLocalName().equals("action-description");
            break;

        case XMLStreamReader.CHARACTERS :
            if( action ){
                String act = reader.getText();
                System.out.println("Action trouvées " + act);

                String[] praxiscmd = act.split("_");
                if("CREATE".equals(praxiscmd[0])){
                    Create c = new Create(praxiscmd[1], praxiscmd[2], null);
                    actionsMap.put(praxiscmd[1], c);
                } else if("DELETE".equals(praxiscmd[0])){
                    Delete d = new Delete(praxiscmd[1],praxiscmd[2], null);
                    actionsMap.put(praxiscmd[1], d);
                } else if ("ADDPROPERTY".equals(praxiscmd[0])) {
                    AddProperty ap = new AddProperty(praxiscmd[1],
                            praxiscmd[2], praxiscmd[3], null);
                    actionsMap.put(praxiscmd[1], ap);
                } else if ("ADDREFERENCE".equals(praxiscmd[0])) {
                    AddReference ar = new AddReference(praxiscmd[1],
                            praxiscmd[2], praxiscmd[3], null);
                    actionsMap.put(praxiscmd[1], ar);
                } else if ("REMPROPERTY".equals(praxiscmd[0])) {
                    RemProperty rp = new RemProperty(praxiscmd[1],
                            praxiscmd[2], praxiscmd[3], null);
                    actionsMap.put(praxiscmd[1], rp);
                } else if ("REMREFERENCE".equals(praxiscmd[0])) {
                    RemReference rr = new RemReference(praxiscmd[1],
                            praxiscmd[2], praxiscmd[3], null);
                    actionsMap.put(praxiscmd[1], rr);
                }
            }
        }
    }

Bekomme ich diese Fehler auf der Zeile : int type = reader.next():

 javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Premature end of file.
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:584)
    at fr.lip6.graphelex.TelexImpl.parse(TelexImpl.java:147)
    at fr.lip6.graphelex.TelexImpl.sendHttpRequest(TelexImpl.java:264)
    at fr.lip6.graphelex.TelexImpl.schedules(TelexImpl.java:116)
    at fr.lip6.graphelex.MapperImpl.send(MapperImpl.java:92)
    at fr.lip6.graphelex.GraphElexAgent.executeCycle(GraphElexAgent.java:81)
    at praxis.guidance.agent.Agent.run(Agent.java:71)
    at java.lang.Thread.run(Thread.java:636)

Verstehe ich nicht, was ist das problem, da ich den gleichen parser für einen anderen Fall und es perfekt funktioniert.
Hier ist ein Beispiel eines XML-streams erhielt ich von einem server :

  <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  <responses>
   <executed-commands>
      <command><name>GETLASTSCEDULES</name>
      <status-code>200</status-code>
      <description>last schedule returned</description>
      </command>
     </executed-commands>
       <schedules><schedule><schedule-id>0</schedule-id>
       <doc-id>/telexDocuments/doc.dox</doc-id>
       <actions>
         <action>
          <action-description>CREATE__8VtAMXv4EeCwaM2v2VqUyg_Model</action-description>  
         <action-id>/telexDocuments/doc.dox:Peer#server2:hephaistos:0:15</action-id>
        </action>
      </actions>
      <non-actions/></schedule></schedules>
      <get-constraints/>
</responses>

Kann mir jemand ein paar Ratschläge geben ?

BEARBEITEN :
Ich kann die Antwort auf meine Frage. Das problem war, als erhielt ich die Antwort vom server InputStream, ich Lesen parse. Wie Sie vielleicht wissen, in Java, einmal ein InputStream ist Lesen analysiert, ist es automatisch schließen. Dinge, die wir manchmal vergessen. Vielen Dank für die Dokumentation

Werde ich korrigieren, dass rasch
Sollten Sie die Antwort auf Ihre Frage mit der Lösung, die Sie gefunden. Dies wird nützlich sein für andere.
Ich habe dieses Problem derzeit und würde gerne sehen, was die Auflösung ist. Bitte stellen.
Hi tut mir Leid. Es ist schon eine Weile her, dass ich nicht die Verbindung zu stackoverflow. Die Antwort ist sehr einfach. In meinem Programm, bevor ich namens der Methode, die ich analysiert habe, verwende ich zum anzeigen der content-input-Stream, um zu sehen, was ich erhalte. Die Tatsache ist, dass, sobald Sie Lesen/analysieren Ihre inpustream, wird es automatisch zu schließen. Siehe den link unten. Also, wenn ich nenne meine Methode parse, die Inputstream-parameter war bereits in der Nähe, das ist der Grund, warum ich fing diese Fehler.
es gibt keine richtige Lösung. Alles klar ist auf der javadoc-link gab ich

InformationsquelleAutor Dimitri | 2011-05-12

Schreibe einen Kommentar