AndroidスタジオでドキュメントビルダとNodeListを使用してXMLドキュメントを解析しています。私は以前、xmlが間違っていて、アンパサンドがエスケープされていないことが判明しました。 W3 XMLバリデータでこれものの、ダブルチェックの世話をした後、私はまだ予期しないトークンエラーが表示されます。Androidスタジオでドキュメントビルダーを使用すると予期しないトークン(<)が発生する
e: "org.xml.sax.SAXParseException: Unexpected token (position:TEXT \n \n 601\n [email protected]:1 in [email protected])"
しかし、私は、XMLを開き、ラインを見たとき、私は何も表示されないために言及厄介であると考えられます:
... ...
5257 <WebSvcLocation>
5258 <Id>1521981</Id>
5259 <Name>Warehouse: Row 3</Name>
5260 <SiteName>Warehouse</SiteName>
5261 </WebSvcLocation>
5262 </ArrayOfWebSvcLocation>
xmlも非印刷文字でチェックしていますが、何も見つかりませんでした。私は読んしようとしているXMLがhereをホストされている
public List<Location> SpinnerXML(String xml){
List<Location> list = new ArrayList<Location>();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
InputSource is;
String s = xml.replaceAll("[&]"," and ");
try {
builder = factory.newDocumentBuilder();
is = new InputSource(new StringReader(s));
Document doc = builder.parse(is);
NodeList lt = doc.getElementsByTagName("WebSvcLocation");
int id;
String name,siteName;
for (int i = 0; i < lt.getLength(); i++) {
Element el = (Element) lt.item(i);
id = Integer.parseInt(getValue(el, "Id"));
name = getValue(el, "Name");
siteName = getValue(el, "SiteName");
list.add(new Location(id, name, siteName));
}
} catch (ParserConfigurationException e){
} catch (SAXException e){
e.printStackTrace();
} catch (IOException e){
}
return list;
}
:以下は、私が使用しているコードです。
ありがとうございました!
このWebSvcLocation要素全体のデータを共有できますか? (おそらく開始タグも存在する)。また、5262後の行は何ですか? – khriskooper
5262の後にはオープンラインのみが存在し、それ以外の場合はドキュメントの最後です。 WebSvcLocation要素全体を含めるように質問を編集します。 – charwayne
ええと、XMLファイルがすべて良かったかどうかを再確認します。正しいエンコード/行末/文字セットなどを使用していますか? XMLファイルをどこかにホストすることができるので、それを確認できますか? – khriskooper