0

Suppose I have an XML statement as below:

<expression>
<refobj>[Sales Volume (Actual)]</refobj> - <refobj>[Sales Volume (Target)]</refobj>
</expression>

How can I parse this expression in Java? My Java output should be a String :

[Sales Volume (Actual)]-[Sales Volume (Target)]

I am parsing my XML file to java using DOM parser.

4
  • 1
    Can you post your code using DOM parser? Commented Nov 27, 2014 at 3:43
  • 1
    You would use a DocumentBuilderFactory to create a DocumentBuilder, and then use that to parse the XML into an instance of org.w3c.dom.Document. What have you written so far? Commented Nov 27, 2014 at 3:52
  • Hi, I am able to parse all the normal XML tags in Java, but this is an expression. I know how to retrieve [Sales Volume(Actual)] and [Sales Volume(Target)], but then how should I retrieve the minus sign from the XML expression in java? Commented Nov 27, 2014 at 4:43
  • Is dropping the whitespace around the hyphen intentional, and part of the requirement? Commented Nov 27, 2014 at 9:23

1 Answer 1

1

You don't need to grovel around the nodes in the DOM in this way, you can use a simple XPath expression: normalize-space(/expression).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.