I로 비누 봉투 다음과 같은 XML을 가지고 자바 String
:JDOM을 사용하여 비누 봉투를 제거하고 나머지 XML을 문자열로 반환하려면 어떻게해야합니까?
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<MyStartElement xmlns="http://www.example.com/service">
...
내가 hamcrest 나중에 그것에 XML-정합 기 확장 https://code.google.com/p/xml-matchers를 사용할 수 있도록하려면,하지만 처음에는 없애 싶어 비누 봉투.
JDOM 2.0.5를 사용하여 비누 봉투를 제거하고 String
으로 남아있는 XML (예 : MyStartElement
루트로 시작)을 다시 가져올 수 있습니까?
SAXBuilder builder = new SAXBuilder();
Document document = (Document) builder.build(toInputStream(THE_XML));
Namespace ns = Namespace
.getNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
Namespace ns2 = Namespace
.getNamespace("http://www.example.com/service");
Element response = document.getRootElement()
.getChild("Body", ns)
.getChild("MyStartElement", ns2);
System.out.println(new XMLOutputter().outputString(new Document(response)));
이 반환 : 스레드 "주요"org.jdom2.IllegalAddException에서 예외 : 콘텐츠가 이미 기존의 부모가 "비누 : 바디"
I
나는 다음과 같은 시도 유사한 설정이있어서 어디서 전화했는지System.out.println(new XMLOutputter().outputString(new Document(response)));
하지만 SOAP 봉투를 포함한 전체 XML을 반환했습니다.
JDOM을 사용하여 XML에서 비누 봉투를 벗겨 내고 String
을 다시 얻으려면 어떻게해야합니까?
보너스 질문 :
- 는 JDOM이 좋은 소개/튜토리얼이 있습니까? (웹 사이트에는 JavaDocs 만있는 것 같습니다. 시작하기가 약간 어려워집니다 ...)
- JDOM을 사용하는 것이이 코드의 맨 위에있는 것 같습니다. 더 쉬운 방법으로 이것을하는 방법에 대한 제안?