첫 번째 두 서비스 작성자의 이름을 가져오고 싶습니다. Java get XML 노드
난 다음 XML 예제가 있습니다<ServiceSchema:id>10</ServiceSchema:id>
<ServiceSchema:name>Service 10</ServiceSchema:name>
<ServiceSchema:authorInfos>
<ServiceSchema:authorInfo>
<ServiceSchema:id>1</ServiceSchema:id>
<ServiceSchema:name>Service Author 1</ServiceSchema:name>
<ServiceSchema:authorInfo>
<ServiceSchema:authorInfo>
<ServiceSchema:id>2</ServiceSchema:id>
<ServiceSchema:name>Service Author 2</ServiceSchema:name>
<ServiceSchema:authorInfo>
</ServiceSchema:authorInfos>
<ServiceSchema:requirements>
<ServiceSchema:requirement>
<ServiceSchema:id>1</ServiceSchema:id>
<ServiceSchema:name>Requirement 1</ServiceSchema:name>
<ServiceSchema:authorInfos>
<ServiceSchema:authorInfo>
<ServiceSchema:id>5</ServiceSchema:id>
<ServiceSchema:name> Requirement Author 5</ServiceSchema:name>
<ServiceSchema:authorInfo>
</ServiceSchema:authorInfos>
</ServiceSchema:requirement>
.....
나는 다음과 같은 코드를 사용하여 모든 이름 노드 얻을 수
:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource inputSource = new InputSource(new ByteArrayInputStream (xml.getBytes("utf-8")));
Document xmldocument = db.parse(inputSource);
NodeList nodeList = xmldocument.getElementsByTagNameNS("*", "name");
을하지만 난이의 이름 만 활용하는 방법을 모른다 외부 저자.
감사합니다.
업데이트 :
내가 완전히 수행하려고하는 것은 : 나는 서로 다른 노드에 대해 서로 다른 xml 파일을 검색 할 수 있습니다. 위의 xml 파일은 예제로 사용되었습니다. 예를 들어
:
searchElementsXml = new String[]{"name", "id", "version", "description", "keywords", "authorInfos.authorInfo.name", "status"};
나는 많은 값이 발생할 수있는 필드가 있습니다. 저자 정보처럼. 좋은 해결책이 거기가
NodeList nodes = doc.getElementsByTagName("ServiceSchema:authorInfos:authorinfo:name");
:
그래서 내가 뭔가를해야합니까?
당신이 출력 노드로 기대 정확히 추가하시기 바랍니다에게 있습니다. – MrSmith42