This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to read xml using DOM Parser

 
Digvijay Singhania
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<?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
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you enter that exact phrase into a search engine, you'll get some amazingly on-topic results.
 
Komari raj
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks the problem is solved
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic