ERLEDIGT
JA
JA
ANTWORTEN
5
5
ZUGRIFFE
238
238
EMPFEHLEN
-
Moin!
Ich stehe hier gerade vor einem kleinen Rätsel. Ich versuche einen einfachen MD5-Hash (in Zeile 10 der Datei) als String aus einer XML-Datei herauszulesen, dazu verwende ich DOM (JAXP). Das sollte eigentlich ganz einfach sein, die Codeausführung bricht jedoch (wie ich nach einigem Debuggen inzwischen weiß) immer bei der markierten Anweisung ab, völlig ohne Kommentar. Ich vermute es ist ein Problem mit der XML, weiß es aber nicht genau. Das die XML etwas komisch ist und dass da auch ein paar Sachen fehlen, damit sie valide ist weiß ich, kann es aber leider nicht ändern, weil die XML von extern kommt, allerdings sollte das dennoch gehen.
Ich hänge mal Code und XML an. Irgendwer eine Idee?
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); factory.setNamespaceAware(false); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(file); //Abbruch Element root = document.getDocumentElement(); Element imageAsset = (Element) root.getElementsByTagName("imageAssetMap"); Element entry = (Element) imageAsset.getElementsByTagName("entry"); Element md5Key = (Element) entry.getElementsByTagName("net.rptools.lib.MD5Key"); Element id = (Element) md5Key.getElementsByTagName("id"); String md5 = id.getNodeValue();
Code xml:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
<net.rptools.maptool.model.Token> <id> <baGUID>wKiyCHo/AztFAAAAAAAyCA==</baGUID> </id> <beingImpersonated>false</beingImpersonated> <imageAssetMap> <entry> <null/> <net.rptools.lib.MD5Key> <id>a14ef24089672177e6daaa3e3675dcf4</id> </net.rptools.lib.MD5Key> </entry> </imageAssetMap> <x>950</x> <y>400</y> <z>4</z> <anchorX>0</anchorX> <anchorY>0</anchorY> <sizeScale>1.0</sizeScale> <lastX>0</lastX> <lastY>0</lastY> <snapToScale>true</snapToScale> <width>72</width> <height>100</height> <scaleX>1.0</scaleX> <scaleY>1.0</scaleY> <sizeMap> <entry> <java-class>net.rptools.maptool.model.SquareGrid</java-class> <net.rptools.maptool.model.GUID> <baGUID>fwABAc9lFSoFAAAAKgABAQ==</baGUID> </net.rptools.maptool.model.GUID> </entry> </sizeMap> <snapToGrid>true</snapToGrid> <isVisible>true</isVisible> <name>Rhandarja</name> <ownerType>0</ownerType> <tokenShape>SQUARE</tokenShape> <tokenType>PC</tokenType> <layer>TOKEN</layer> <propertyType>Basic</propertyType> <isFlippedX>false</isFlippedX> <isFlippedY>false</isFlippedY> <portraitImage> <id>3a98f82f96a857a13ef4e942ed5eace9</id> </portraitImage> <sightType>Normal</sightType> <hasSight>true</hasSight> <label>liebes Mädchen</label> <gmName>Schoene der Nacht</gmName> <state> <entry> <string>kampfunfaehig</string> <boolean>false</boolean> </entry> <entry> <string>tot</string> <boolean>false</boolean> </entry> <entry> <string>lebensbedroht</string> <boolean>false</boolean> </entry> <entry> <string>AE</string> <big-decimal>1</big-decimal> </entry> <entry> <string>AU</string> <big-decimal>1</big-decimal> </entry> <entry> <string>verwundet</string> <boolean>false</boolean> </entry> <entry> <string>LE</string> <big-decimal>1</big-decimal> </entry> <entry> <string>am_Boden</string> <boolean>false</boolean> </entry> </state> <propertyMap class="net.rptools.CaseInsensitiveHashMap"> <store> <entry> <string>eigenschaften</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>Eigenschaften</key> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>wunden</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>Wunden</key> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>kap</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>KaP</key> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>maxkap</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>MaxKaP</key> <value class="string">0</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>ko</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>KO</key> <value class="string">10</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>mu</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>MU</key> <value class="string">11</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>lep</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>LeP</key> <value class="string">23</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>ge</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>GE</key> <value class="string">12</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>kk</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>KK</key> <value class="string">10</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>ini</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>INI</key> <value class="string">9</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>in</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>IN</key> <value class="string">13</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>kl</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>KL</key> <value class="string">12</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>maxlep</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>MaxLeP</key> <value class="string">23</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>aup</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>AuP</key> <value class="string">27</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>ff</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>FF</key> <value class="string">10</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>-----------------------------------</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>-----------------------------------</key> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>maxasp</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>MaxAsP</key> <value class="string">33</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>ch</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>CH</key> <value class="string">16</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>asp</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>AsP</key> <value class="string">33</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>maxaup</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>MaxAuP</key> <value class="string">27</value> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> <entry> <string>basiswerte</string> <net.rptools.CaseInsensitiveHashMap_-KeyValue> <key>Basiswerte</key> <outer-class reference="../../../.."/> </net.rptools.CaseInsensitiveHashMap_-KeyValue> </entry> </store> </propertyMap> <macroPropertiesMap/> <speechMap/> </net.rptools.maptool.model.Token>
Geändert von Cronk (26.04.10 um 21:24 Uhr)
-
Ich schubs' das ganze jetzt mal an...
Übrigens tritt das selbe Problem auch auf, wenn ich versuche das Dokument mit SAX zu parsen (ebenfalls die JAXP Implementierung) sobald ich zum ersten mal next() oder nextTag() aufrufe.
-
28.04.10 15:56 #3
- Registriert seit
- Jun 2005
- Beiträge
- 8.168
Hi.
Das XML Dokument sieht OK aus.
Mach am besten mal ein vollständiges Minimalprogramm bei dem der Fehler auftritt und poste es hier.
GrußIf at first you don't succeed, try again. Then quit. No use being a damn fool about it.
-
Gut, 30 Zeilen....
zeile 19 bricht ohne weitere Meldung ab. Soll heißen der Haltepunkt vor Zeile 19 wird noch erreicht, der vor 21 (20 ist Leerzeile) nicht mehr. "test.xml" ist die oben gepostete XML.
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package de.tutorials.xmltest; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; import java.io.IOException; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse("test.xml"); Element root = document.getDocumentElement(); Element imageAsset = (Element) root.getElementsByTagName("imageAssetMap"); Element entry = (Element) imageAsset.getElementsByTagName("entry"); Element md5Key = (Element) entry.getElementsByTagName("net.rptools.lib.MD5Key"); Element id = (Element) md5Key.getElementsByTagName("id"); System.out.println(id.getNodeValue()); } }
-
28.04.10 16:32 #5
- Registriert seit
- Jun 2005
- Beiträge
- 8.168
Was heißt hier ohne Meldung? Wie führst du das denn aus?
Bei mir kommt:\edit: Den Fehler muß man eigentlich nicht kommentieren, oder? Du rufst dort eine Methode auf, die eine Knotenliste (also mehrere Elemente) zurückliefert.Code :1 2
Exception in thread "main" java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl cannot be cast to org.w3c.dom.Element at TestMain.main(TestMain.java:22)
GrußIf at first you don't succeed, try again. Then quit. No use being a damn fool about it.
-
Hm, kommt bei mir nicht aber Okay, ist tatsächlich nicht weiter zu kommentieren.... Whatever
Ähnliche Themen
-
JAXB - (Fehler beim parsen?) Exception bei Unmarshall
Von eaglestar im Forum JavaAntworten: 4Letzter Beitrag: 23.01.09, 12:44 -
IE-Probleme beim XML-Parsen
Von BMo im Forum Javascript & AjaxAntworten: 2Letzter Beitrag: 25.07.08, 19:36 -
XML parsen mit Sax -> Fehler
Von raphk im Forum JavaAntworten: 2Letzter Beitrag: 09.01.06, 14:32 -
Problem beim XML-Parsen
Von McQueen im Forum PHPAntworten: 0Letzter Beitrag: 06.03.05, 19:44 -
Problem beim Parsen von XML mit SAX
Von Static_Vengeance im Forum JavaAntworten: 1Letzter Beitrag: 26.11.03, 15:11





Zitieren

Login





