File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes how to read xml using DOM Parser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how to read xml using DOM Parser" Watch "how to read xml using DOM Parser" New topic
Author

how to read xml using DOM Parser

Digvijay Singhania
Greenhorn

Joined: Sep 22, 2012
Posts: 9
<?xml version="1.0" encoding="UTF-8"?>
<RELEASE_TEMPLATE>
<TEMPLATE NAME="14C Release Set" SUPER_TEMPLATE="YES" DESCRIPTION="ReleaseSet1(Basic parameters)" ID="0">
<TEMPLATE ID="10" MANDATORY="YES"/>
<TEMPLATE ID="20" MANDATORY="YES"/>
<TEMPLATE ID="30" MANDATORY="YES" >
<CROSSVALIDATE CROSS_VALIDATION_ID="10" SOURCE_PARAM="COUNTRY_DIRECTORY" SOURCE_FIELD="BASE_CRNCY" TARGET_TEMPLATEID="1" TARGET_PARAM="CURRENCY_DIRECTORY" TARGET_FIELD="CRNCY_CODE_ALPHBTC"/>
<CROSSVALIDATE EXTERNAL_HOOK="YES" ETERNAL_HOOK_ID="1" API_CLASS="com.tcs.bancs.pms.util.Test" METHOD="validate" ARGS="10,20" />
</TEMPLATE>

<TEMPLATE NAME="Release Set 1" DESCRIPTION="ReleaseSet1(Basic parameters)" ID="1">
<PARAM NAME="COUNTRY_DIRECTORY" MANDATORY="YES"/>
<PARAM NAME="CURRENCY_DIRECTORY" MANDATORY="YES"/>
<PARAM NAME="CURRENCY_DETAILS" MANDATORY="YES"/>
<PARAM NAME="OPERATIONAL_UNIT" MANDATORY="NO" />
<PARAM NAME="PP_CONFIG_PARAM" MANDATORY="YES" />
</TEMPLATE>


</RELEASE_TEMPLATE>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41865
    
  63
If you enter that exact phrase into a search engine, you'll get some amazingly on-topic results.


Ping & DNS - my free Android networking tools app
Komari raj
Ranch Hand

Joined: Dec 12, 2008
Posts: 43

HI Digvijay
Please find the sample code to get the xml content by attribute, it might be helpful for you..

?xml version="1.0" encoding="UTF-8"?>
<!-- bookstores.xml -->
<bookstore>
<book ISBNUMBER="10001">
<title>JAVA1</title>
<author>Headfirst</author>
<category>Programming</category>
<year>2013</year>
</book>
<book ISBNUMBER="10002">
<title>JAVA2</title>
<author>Complete reference</author>
<category>Tutorial</category>
<year>2004</year>
</book>
</bookstore>

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = factory.newDocumentBuilder();
File file = new File("bookStores.xml");
Document doc = docBuilder.parse(file);

// Get a list of all elements in the document
// The wild card * matches all tags
NodeList list = doc.getElementsByTagName("*");
int bookCount = 0;
for (int i = 0; i < list.getLength(); i++) {
// Get the elements book (attribute isbn), title, author
Element element = (Element)list.item(i);
String nodeName = element.getNodeName();
if (nodeName.equals("book")) {
String isbn = element.getAttribute("ISBNUMBER");
System.out.println("\tISBN:\t" + isbn);
} else if (nodeName.equals("title")) {
System.out.println("\tTitle:\t"
+ element.getChildNodes().item(0).getNodeValue());
} else if (nodeName.equals("author")) {
System.out.println("\tAuthor:\t"
+ element.getChildNodes().item(0).getNodeValue());
}
}



Regards
Raju
Digvijay Singhania
Greenhorn

Joined: Sep 22, 2012
Posts: 9
thanks the problem is solved
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to read xml using DOM Parser