0

I wonder if there is an already existing system out there that does the following:

Consider a well-formed XML document:

<?xml version="1.0" encoding="UTF-8"?>


<root>
    <test>
    <name>Test</name>
    <complex>
        <value>Hello</value>
    </complex>
    </test>
</root>

Now what I want to do is retrieve "Hello" for example like this:

aSuitableClass.getString("test.complex.value");

I have made a small library that does this for JSON but I want to know if there is something like this for XML already out there. I know of XPath but that's not what I want because it uses "/" and so on.

If I had to make this myself I would assume DOM is the easiest for this as it is already in a tree structure. I would just have to create a string mapping.

Limnic
  • 1,826
  • 1
  • 20
  • 45

1 Answers1

1

If you want to do something like

aSuitableClass.getString("test.complex.value");

you could replace the '.' characters to '/' and convert your query to an XPath expression in the getString method. I think that's your simplest option. Here's an example of XPath How to read XML using XPath in Java

Community
  • 1
  • 1
Balint Domokos
  • 1,021
  • 8
  • 12