문제

Hello I am have this code

   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);

And it's ouput like this:

 [Element: <Action__CompIntfc__CIName/>]

but I am need only clear Action_CompIntfc_CIName

도움이 되었습니까?

해결책

To get the xml tag name you have to change this:

   List listAttributrBody = e.getChildren();
   String element2 = listAttributrBody.get(0).toString();

To this:

    List<Element> listAttributrBody = e.getChildren();
    String element2 = listAttributrBody.get(0).getName();

If you are using older version (1.1) you are not allowed to use generics () then you have to do this:

   List listAttributrBody = e.getChildren();
   Element el2 = (Element)listAttributrBody.get(0);
   String element2 = el2.getName();

You can read more about available methods in jdom api

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top