javaxmlxpathvtd-xml

check XPath in VTD-XML is evaluating to XML Tag (or) Text (or) List of Tag (or) list of Text


Consider the below XML sample Structure as an input. I am using VTD-XML:2.11 for parsing the XML using Java-8. The scenarios is like I need to parse the below XML depending on the provided XPath and return a List that contains the values evaluated by the XPath. At any point the XML that needs to be parsed and the XPath are not fixed each time my parse will have new XML as an input with new XPath.

Ex1: XPath: //CATALOG/CD/TITLE/text()
 output: - Empire Burlesque
         - Still got the blues
         - Hide your heart

Ex2: XPath: //CATALOG/CD/TITLE
 output: - <TITLE id="1">Empire Burlesque</TITLE>
         - <TITLE>Still got the blues</TITLE>
         - <TITLE>Hide your heart</TITLE>

One of main problem that I am facing is I am not able to check if the evaluated XPath is a XML Element or XML text?.

Note: I do not want to check if the given XPath is ending with "text()" to know if the XPath evaluation will be a text or Element.

<CATALOG>
 <CD>
    <TITLE id="1">Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1985</YEAR>
 </CD>
 <CD>
    <TITLE>Still got the blues</TITLE>
    <ARTIST>Gary More</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Virgin redords</COMPANY>
    <PRICE>10.20</PRICE>
    <YEAR>1990</YEAR>
 </CD>
 <CD>
    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tyler</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS Records</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1988</YEAR>
 </CD>
</CATALOG>

Please let me know if any one would like me to add extra information in order to fully understand my problem.


Solution

  • VTD-XML's VTDNav object allows you to check the identity of a token by using its getTokenType() method call.... Is this what you are looking for?