私はこのようなxmlを持っています:
<Message xmlns="uri_of_message">
<VendorId>1234</VendorId>
<SequenceNumber>1</SequenceNumber>
...other important headers...
<Data>
<Functions xmlns="uri_of_functions_subxml">
<Function1 attr="sth">
<Info>Some_Info</Info>
</Function1>
<Function2>
<Info>Some_Info</Info>
</Function2>
...Functions n...
</Functions>
</Data>
</Message>
内部xmlを抽出する必要があります
<Functions xmlns="uri_of_functions_subxml">
<Function1 attr="sth">
<Info>Some_Info</Info>
</Function1>
<Function2>
<Info>Some_Info</Info>
</Function2>
...Functions n...
</Functions>
私は最初に文字メソッドで内部xmlを取得しようとしました:
public void startElement(String uri, String localName, String tagName, Attributes attributes) throws SAXException {
if (tagName.equalsIgnoreCase("Data")){
buffer = new StringBuffer();}
}
public void characters(char[] ch, int start, int length) throws SAXException {
if (buffer != null) {
buffer.append(new String(ch, start, length).trim());
}
}
public void endElement(String uri, String localName, String tagName) throws SAXException {
if (tagName.equalsIgnoreCase("Data")){
innerXML = buffer.toString().trim();
}
しかし、文字メソッドが xml を適切に収集していないことに気付きました。「<」、「>」などの特殊文字を拒否した可能性があります。
以下のリンクには同じ質問が含まれていますが、外側のxmlは一種のハンドシェイク信号として処理する必要があり、内側のxmlはまったく異なる方法で処理する必要があるため、答えは私には当てはまりません.
Java XML 解析: SAX を使用した内部 XML の取得
私が必要とするのは、内部の xml を適切に収集することだけです。しかし、それを行う方法は?前もって感謝します..