1
次のように解析する上でアイデアがあります。私はちょうど各価値を得たいと思う。ALM XMLデータをJavaで解析する
<Entities TotalResults="3">
<Entity Type="defect">
<Fields>
<Field Name="id">
<Value>2</Value>
</Field>
<Field Name="project">
<Value>P10</Value>
</Field>
<Field Name="name">
<Value>MMW - Issue with Referral check upon deployment of pre-assembly test</Value>
</Field>
</Fields>
<RelatedEntities/>
</Entity>
<Entity Type="defect">
<Fields>
<Field Name="id">
<Value>777</Value>
</Field>
<Field Name="project">
<Value>P10</Value>
</Field>
<Field Name="name">
<Value>R6 throwing CORBA transaction error on product set-up screen on every bundle selection</Value>
</Field>
</Fields>
<RelatedEntities/>
</Entity>
私がしようとしているコードは以下の通りです - ファイルfXmlFile =新しいファイル( "D:/Java/file.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("Entity");
System.out.println("----------------------------");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
System.out.println("Name : " + eElement.getAttribute("Field"));
あなたはすでに書いたコードを表示することができればそれが役立つだろう。 –
このチュートリアルを見ると、XMLデータの解析に役立ちます。https://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/ –