你好我有这个代码
Document rootElement = saxBuilder.build(inputXML);
Element element = rootElement.getRootElement();
Namespace ns = Namespace.getNamespace("http://schemas.xmlsoap.org/soap/envelope/");
Element e = element.getChild("Body", ns);
Format format=Format.getCompactFormat();
List listAttributrBody = e.getChildren();
String element2 = listAttributrBody.get(0).toString();
System.out.print(element2);
InputStream propfile = new
FileInputStream("/home/igor/IdeaProjects/jdomtest/src/main/resources/properties.xml");
Properties properties = new Properties();
properties.load(propfile);
String pathToOutput=properties.getProperty(element2);
//System.out.println(pathToOutput);
它的输出如下:
[Element: <Action__CompIntfc__CIName/>]
但我只需要清楚Action_ CompIntfc _CIName
答案 0 :(得分:1)
要获取xml标记名称,您必须更改此内容:
List listAttributrBody = e.getChildren();
String element2 = listAttributrBody.get(0).toString();
对此:
List<Element> listAttributrBody = e.getChildren();
String element2 = listAttributrBody.get(0).getName();
如果您使用的是旧版本(1.1),则不允许使用泛型(),那么您必须这样做:
List listAttributrBody = e.getChildren();
Element el2 = (Element)listAttributrBody.get(0);
String element2 = el2.getName();
您可以阅读有关可用方法的更多信息 jdom api