Y
Y
YV2014-10-29 17:46:45
Java
YV, 2014-10-29 17:46:45

How to make friends XPath and custom XML tree?

There is a custom xml parser. As a result of parsing, a tree is obtained, all the nodes of the tree are in ListMultimap<String, Node>, where the key is the path to the node, for example, "/project/dependencies/dependency".
The tree provides the ability to make 2 types of requests:
1. Go for the text content of a particular node

String artifactId = xmlTree.selectText("/project/artifactId");

2. Go for a sheet of nodes
List<Node> dependencies = xmlTree.selectNodes("/project/dependencies/dependency");

Now you need to be able to select nodes according to specific conditions, for example:
List<Node> testDeps = tree.selectNodes("/project/dependencies/dependency[scope=test]");

It would be possible to take care of your bike, but the deadlines are running out!
So far I have come up with only 2 options:
1. Implement com.w3c.dom to a minimum and delegate to the existing tree (but I'm not sure if I can do it)
2. Parse the file again with another parser and
map all the results of xpath queries into the nodes of "our" tree.
btw if you have a question why not just use a parser for xml -> because it is very important not to break the formatting and the existing file structure during updates, here 90% of the parsers do not immediately fit, and the remaining 10% do not fit under the license.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
YV, 2014-11-20
@targetjump

I decided through Node#setUserData + node delegation from the box.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question