• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to read xml as given below

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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" />
</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>


 
Digvijay Singhania
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my java code is here :

public static Map<String,ReleaseTemplateConfig> readXML(String strFileName) throws Exception {
Document document;
DocumentBuilder documentBuilder;
DocumentBuilderFactory documentBuilderFactory;
File xmlInputFile;
NodeList nodeList;
Boolean flag=false;
Map<String,ReleaseTemplateConfig> releaseViewConfig=new LinkedHashMap<String,ReleaseTemplateConfig>();
ReleaseTemplateConfig relConfig =null;
LinkedHashMap<String, String> fieldList =null;
try {
xmlInputFile = new File(strFileName);
documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilder = documentBuilderFactory.newDocumentBuilder();
document = documentBuilder.parse(xmlInputFile);
nodeList = document.getElementsByTagName("*");
ArrayList< CrossValidationBean> al=null;
String paramName=null;
Boolean supertemplateFlag=true;
LinkedHashMap<String,ArrayList<CrossValidationBean>> hmap=new LinkedHashMap<String,ArrayList<CrossValidationBean>>();
document.getDocumentElement().normalize();
for (int index = 0; index < nodeList.getLength(); index++) {
Node node = nodeList.item(index);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;


if (!element.getTagName().startsWith(ParamConstants.RELEASE_TEMPLATE)){

if(element.getTagName().startsWith(ParamConstants.TEMPLATE) && !"".equals(element.getAttribute(ParamConstants.ID)) && supertemplateFlag){

relConfig=new ReleaseTemplateConfig();
relConfig.setTemplateId(element.getAttribute(ParamConstants.ID));
System.out.println("id"+element.getAttribute(ParamConstants.ID));
relConfig.setTemplateName(element.getAttribute(ParamConstants.NAME));
System.out.println("Name"+element.getAttribute(ParamConstants.NAME));
relConfig.setTemplateDesc(element.getAttribute(ParamConstants.DESCRIPTION));
System.out.println("Description"+element.getAttribute(ParamConstants.DESCRIPTION));
supertemplateFlag=false;
if(element.getTagName().startsWith(ParamConstants.TEMPLATE) && !"".equals(element.getAttribute(ParamConstants.ID))){
System.out.println("id"+element.getAttribute(ParamConstants.ID));
System.out.println("mandatory"+element.getAttribute(ParamConstants.MANDATORY));
}}}
 
reply
    Bookmark Topic Watch Topic
  • New Topic