Reputation: 9
<pko:POImport xmlns:xs="http://XMLSchema-instance"
xmlns:pko="hello"
xs:schemaLocation=" PlannedQuantityImport.xsd" tag="TAG" notes="These are my notes" totalqtypctmin="2" totalqtypctmax="3" mismatchthresholdpct="8.0">
<prodgrp id="100067">
<prodid>SYC87948427320</prodid>
<locgrp id="100067">
<geoid>30454</geoid>
<geoid>30982</geoid>
<quantity date="2010-12-11" sequence="1" prodid="87948427320">600</quantity>
</locgrp>
</prodgrp>
</pko:POImport>
I want to get the data corresponding to
tag, notes,totalqtypctmin,totalqtypctmax,mismatchthresholdpct,prodgrp,prodid,locgroup,geoid etc.
Upvotes: 0
Views: 77
Reputation: 1002
I'd just use string matching.
inputStream = new BufferedReader(new FileReader("file.xml"));
while(inputStream.hasNext()){
String s=inputStream.next();
if(s.indexOf("totalqtypctmax")==-1)
continue;
String k = s.split("totalqtypctmax=\"")[1].split("\"")[0];
System.out.println("The value of totalqtypctmax is "+k);
}
Java isn't my first language, so pardon any silly mistakes.
EDIT: The only reason I'm using string matching instead of a standard XML parser, which is obviously recommended for more elaborate XML files, is because, in this case, your requirements seem very specific.
Upvotes: 1
Reputation: 11756
Their are various methods for parsing in java you could either use
These are included in the JDK by default you can also use JDOM Goto the following link to more info http://www.mkyong.com/tutorials/java-xml-tutorials/
Upvotes: 0
Reputation: 68945
You will need XML parser to extract information from a XML using your desired xPath. Refer to this Best XML parser for Java.
Upvotes: 1