0

I have an xml which web resource and I have String to URL where the xml is and in it I have to find specific tag someTag and to get its text content. How to do it in java?

I search but only find ways where there is specific XPath,but in my case I do not know where someTag can be. Which parser to use? And how to implement it?

Xelian
  • 16,680
  • 25
  • 99
  • 152
  • If you know XML, you can create JAXB object and unmarshal xml into object. This way it will be more easy. – Sushant Tambare Jan 06 '15 at 17:52
  • Looks like this question has already been asked : http://stackoverflow.com/questions/7373567/java-how-to-read-and-write-xml-files. Also see [http://www.mkyong.com/tutorials/java-xml-tutorials/] – Ravindra HV Jan 06 '15 at 17:53
  • XPath is a part of the standard Java library. It can parse XML. – Sid Jan 06 '15 at 17:54
  • 1
    A tag name by itself can be an XPath. You don't need to know where it is. – erickson Jan 06 '15 at 17:58

2 Answers2

2

An XPath expression starting with a double slash will find an element anywhere:

 XPathExpression xpw = xpath.compile( "//someTag" );
laune
  • 31,114
  • 3
  • 29
  • 42
0

I recently used transformer class to process stix xml messages. http://docs.oracle.com/javase/7/docs/api/javax/xml/transform/Transformer.html

Krunal
  • 7,048
  • 1
  • 18
  • 19