0
나는 같은 이름의 태그가 다양한 xml 문서를 가지고있다. 어떻게하면 자식 요소의 수와 그 값을 얻을 수 있습니까?dom xml 파서 자바, 같은 태그
<Question>
<QuestionText>ABC?</QuestionText>
<Option>A1 - XYZ</Option>
<Option>A2 - WXY</Option>
<Option>A2 - HJK</Option>
<ID>1</ID>
</Question>
<Question>
<QuestionText>ERY?</QuestionText>
<QuestionText>NNN?</QuestionText>
<QuestionText>KKKK?</QuestionText>
<ID>2</ID>
</Question>
출력 읽어야 ...
나는했지만,이 고장이 나는 해결책ID : 2 1 있음 QuestionText 3 옵션 QuestionText 1 ABC? 옵션 1 : A1 - XYZ 옵션 2 : A2 - wxy에 옵션 3 : A2 - HJK
ID : 1 가지고 3 QuestionText 0 옵션 QuestionText 1.ERY? QuestionText 2.NNN? 질문 텍스트 3.KKKK?
getTagValue()
무엇
Element eElement = (Element) nNode;
getTagValue("QuestionText",eElement);
getTagValue("Option",eElement);
private static void getTagValue(String sTag, Element eElement){
NodeList nlList = eElement.getElementsByTagName(sTag);
System.out.println("Size of nodelist:"+nlList.getLength());
for(int i=0;i<nlList.getLength();i++){
NodeList kList= eElement.getElementsByTagName(sTag).item(i).getChildNodes();
Node kValue = (Node) kList.item(0);
System.out.println("Node Value:"+kValue.getNodeValue());
}
}
@hilal에서
getTagValue()
이다는 works..but 어떻게 ..well..i 그 튜토리얼은 자기를 사용하고 내가 이해 감사 제 질문이 다른 것입니다. 다시 한번보십시오. –@raqz 질문에 대답하지 않으면 왜 이것을 답으로 표시 하시겠습니까? – user183037