Java JAXB解组XML并获取所有可识别的标记

Java JAXB解组XML并获取所有可识别的标记,java,xml,jaxb,Java,Xml,Jaxb,是否有一种方法可以从使用JAXB解压xml后返回的内容树中检索所有已识别的标记 Unmarshaller unmarshaller = getJaxbContext(p.getName()).createUnmarshaller(); unmarshaller.setSchema(getJaxbSchema(p.getName(), getJaxbContext(p.getName()))); //p is the JAXB package Object o = unmars

是否有一种方法可以从使用JAXB解压xml后返回的内容树中检索所有已识别的标记

Unmarshaller unmarshaller = getJaxbContext(p.getName()).createUnmarshaller();

    unmarshaller.setSchema(getJaxbSchema(p.getName(), getJaxbContext(p.getName())));
//p is the JAXB package

    Object o = unmarshaller.unmarshal(in); // the input stream of xml

    if(o instanceof JAXBElement){
        o = ((JAXBElement)o).getValue();
    }
例如,如果下面看到的xml是输入流,我希望得到如下字符串的列表[“parentTag”、“childTag1”、“childTag2”、“childTag3”]


您可以使用
getElementsByTagName(“*”)

NodeList NodeList=doc.getElementsByTagName(“*”);
对于(int i=0;i
<parentTag>
  <childTag1>
    <childTag2>
    </childTag2>
  </childTag1>
  <childTag3/>
</parentTag>
NodeList nodeList = doc.getElementsByTagName("*");
for (int i=0; i<list.getLength(); i++) {
     // Get element
     Element element = (Element) list.item(i);
     // element.getNodeName() is the tag name
}