Another Java XML Library Question

I never liked XML, and I always tried to avoid it. And the day has come.

When I tried to parse XML, it was very difficult. I used the DOM parser, when I called getChildNodes()for Node, it returned NodeList. I had to use casting when using XPath.

Is there any Java XML parsing library similar to the WebDriver WebElement mechanism where it getChildNodes()returns List<Node>(or Collection, Iterable, etc.), I do not need to do the casting. In other words, is there an XML parser library that is elegant and simple.

The library can only be read, I do not need manipulation.

+3
source share
6 answers

dom4j started using generics and Collection with version 2.0.

The documentation is not very good for 2.0, but the old documentation works well.

0
source

I would explore JDOM as a much more convenient API.

eg. Element.getChildren()returns a list of objects Element(unfortunately, it was not generalized, but the API document is clear).

dom4j is another alternative (again, not generalized).

+3
source

, XML. , , , . / - SOAP. , Spring -WS JAXB. - SOAP XML Java, / . , , , , SOAP, .. XML, , JAXB.

?

+2

JAXB. , XML ( ), jaxb compiler xjc Java XML. XML. , .

0

, , .

XML- Java beans XML beans, JAXB, XMLBeans.

XML , JDOM, DOM SAX.

List :

Iterator itr = (currentElement.getChildren()).iterator();
   while(itr.hasNext()) {
     Element oneLevelDeep = (Element)itr.next();
     List twoLevelsDeep = oneLevelDeep.getChildren();
     // Do something with these children
   }
0

JDOM API , DOM API JDK. , API generics /, .

0

Source: https://habr.com/ru/post/1732858/


All Articles