Above one is the XML file. I need to get the value for the Google analytics from the above xml file
上記のXMLからの出力を取得する必要があります。次のコードを試してみましたが、出力は表示されません これについてお手伝いできますか次のXMLコードのテキストコンテンツを取得する方法
上記のいずれかがXMLファイルです。
:私は2つの問題がありましたあなたはif (node.getTextContent().equals("GA")) {
にライン
if (node.getNodeName()=="GA") {
を変更する必要が
public class Xml {
public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, XPathExpressionException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new FileInputStream(new File("C:\\Users\\VAMSIKRISHNA\\Desktop\\Apache Poi\\appConfig.plist")));
NodeList nodeList=document.getElementsByTagName("key");
NodeList nodeList1=document.getElementsByTagName("string");
for (int i=0; i < nodeList.getLength(); i++) {
for(int j=0;j<nodeList1.getLength();j++) {
Node node = nodeList.item(i);
Node node1=nodeList1.item(j);
if (node.getNodeName()=="GA") {
System.out.println("Nodename"+node1.getNodeName()+" : "+node1.getFirstChild().getTextContent().trim());
}
}
}
}
}
ご連絡いただきありがとうございます。私はurの変更でコードを再編集しました。しかし、次の行にnullポインタ例外を表示しています。System.out.println(node1.getFirstChild()。getTextContent()); – hii
うれしい私は助けることができました。ヌルチェックを追加する必要があります:if(node1.getFirstChild()!= null) – JensS
コードにヌルチェックを追加しました。 – JensS