It's not a secret anymore!*
The moose likes XML and Related Technologies and the fly likes how to read xml as given below 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 as given below " Watch "how to read xml as given below " New topic
Author

how to read xml as given below

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" />
</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

Joined: Sep 22, 2012
Posts: 9
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));
}}}
 
Don't get me started about those stupid light bulbs.
 
subject: how to read xml as given below