J'essaye d'analyser XML en utilisant ce class. Lorsque je tape un fichier simple, cela fonctionne très bien.Java: MalformedByteSequenceException (XML)
<testData>
<text>
odp
</text>
</testData>
Voici mon main
public static void main(String[] args) {
Xml train = new Xml(args[0], "trainingData");
Xml test = new Xml(args[1], "testData");
}
Cependant, quand j'utilise le fichier que je suis arrivé en copiant et collant de MSFT OneNote Bureau, je reçois des erreurs:
Exception in thread "main" java.lang.RuntimeException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
at odp.compling.Xml.rootElement(Xml.java:41)
at odp.compling.Xml.<init>(Xml.java:61)
at odp.compling.ParseTreeAnalysis2.main(ParseTreeAnalysis2.java:10)
Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at odp.compling.Xml.rootElement(Xml.java:33)
... 2 more
Ce qui est à l'origine ce? J'ai édité le fichier XML problématique dans Notepad ++ et changé l'encodage en UTF-8
. Cela a causé un tas de caractères étranges des accents/guillemets spéciaux, que j'ai édités. Est-ce que je ne convertis pas correctement?
(je ne sais pas quoi que ce soit sur les formats d'encodage de texte, dans le cas où vous ne pouvait pas dire.)
comment puis-je générer un tel vidage hexadécimal? –
Sous Unix/Linux/Mac, utilisez "od -x file". Sous Windows, vous devez télécharger un outil, comme celui-ci: http://www.richpasco.org/utilities/hexdump.html –
N'est-ce pas suffisant de ré-encoder le fichier en utilisant un éditeur tel que notepad ++? J'ai rencontré le même problème - un contexte différent (manipulation de xml dans une construction de fourmis) et malheureusement ré-encoder le fichier en UTF-8 (même si c'était déjà UTF-8) n'aidait pas du tout. – AgentKnopf