This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Help Needed in XML!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Help Needed in XML!!" Watch "Help Needed in XML!!" New topic
Author

Help Needed in XML!!

Rajesh Rajaram
Ranch Hand

Joined: Aug 20, 2002
Posts: 63
Dear All,

I have a XML file as below. when i parse it i am getting only the first element value for all the 21 nodes.

<?xml version="1.0" encoding="UTF-8"?>

<RoHSExemptionCheckbox>
<RoHSExemption>1</RoHSExemption>
<RoHSExemption>2a</RoHSExemption>
<RoHSExemption>2b</RoHSExemption>
<RoHSExemption>2c</RoHSExemption>
<RoHSExemption>3</RoHSExemption>
<RoHSExemption>4</RoHSExemption>
<RoHSExemption>5</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
</RoHSExemptionCheckbox>

I am using this java code.

String sRoHSDeclaration = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSDeclaration");
String sSupplierAcceptance = getStringValueFromLevelOneTag(firstDBTagElement,"SupplierAcceptance");
String sRoHSExemption1 = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSExemption");
String sRoHSExemption2 = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSExemption");
String sRoHSExemption3 = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSExemption");
String sRoHSExemption4 = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSExemption");
String sRoHSExemption5 = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSExemption");

thanks in advance.
regards,
Rajesh Rajaram


Rajesh Rajaram
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
It's hard to tell what might be going on because we don't know what the getStringValueFromLevelOneTag method does. If its purpose it to return the first child element with the name of its second parameter, why would you expect it ever not to return the first RoHSExemption element?
Rajesh Rajaram
Ranch Hand

Joined: Aug 20, 2002
Posts: 63
Here is the method.

private static String getStringValueFromLevelOneTag(Element elementpara, String tagName){
NodeList nodelist = null;
Element element = null;
NodeList oNodelist = null;
String returnStr = null;
nodelist = elementpara.getElementsByTagName(tagName);
element = (Element) nodelist.item(0);
oNodelist = element.getChildNodes();
returnStr = nullCheck(oNodelist, element);
return returnStr;
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
element = (Element) nodelist.item(0);

So you are always getting the first element. You need to keep track of how many elements you have retrieved so far, e.g. by incrementing a counter and using that as the index instead of zero.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help Needed in XML!!