Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

XML Help

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

I am trying to parse this particular file, can any one suggest a way of getting the elements.

<?xml version="1.0" encoding="UTF-8"?>
<SubItem name="805">
<HomogeneousMaterial name="Ceramic Body">
<Amount unitOfMeasure="mg" weight="9.43800000" />
<SubstanceCatagory jigLevel="Supplier" name="Oxygen Compond">
<Substance cas="17778802" name="Oxygen">
<Amount unitOfMeasure="mg" weight="2.85872000" />
<SubstanceExemptionList>
<Exemption identity="" />
</SubstanceExemptionList>
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="Supplier" name="Titanium">
<Substance cas="7440326" name="Titanium">
<Amount unitOfMeasure="mg" weight="2.04945000" />
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="Supplier" name="Silver">
<Substance cas="7440224" name="Silver">
<Amount unitOfMeasure="mg" weight="0.03153000" />
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="Supplier" name="Barium">
<Substance cas="7440393" name="Barium">
<Amount unitOfMeasure="mg" weight="1.01947000" />
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="A" name="Lead/Lead Compounds">
<Substance cas="7439921" name="Lead">
<Amount unitOfMeasure="mg" weight="0.13663000" />
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="B" name="Bismuth/Bismuth Compounds">
<Substance cas="7440699" name="Bismuth">
<Amount unitOfMeasure="mg" weight="0.25224000" />
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="Supplier" name="Neodymium">
<Substance cas="7440008" name="Neodymium">
<Amount unitOfMeasure="mg" weight="1.92333000" />
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="Supplier" name="Zirconium">
<Substance cas="7440677" name="Zirconium">
<Amount unitOfMeasure="mg" weight="0.37836000" />
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="Supplier" name="Palladium">
<Substance cas="7440053" name="Palladium">
<Amount unitOfMeasure="mg" weight="0.07357000" />
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="Supplier" name="Miscellaneous">
<Substance>
<Amount unitOfMeasure="mg" weight="0.43091000" />
</Substance>
</SubstanceCatagory>
</HomogeneousMaterial>
<HomogeneousMaterial name="Termination">
<Amount unitOfMeasure="mg" weight="1.07200000" />
<SubstanceCatagory jigLevel="Supplier" name="Silver">
<Substance cas="7440224" name="Silver">
<Amount unitOfMeasure="mg" weight="0.77774000" />
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="Supplier" name="Tin">
<Substance cas="7440315" name="Tin">
<Amount unitOfMeasure="mg" weight="0.16816000" />
</Substance>
</SubstanceCatagory>
<SubstanceCatagory jigLevel="B" name="Nickel (external applications only)">
<Substance cas="7440020" name="Nickel">
<Amount unitOfMeasure="mg" weight="0.12612000" />
</Substance>
</SubstanceCatagory>
</HomogeneousMaterial>
</SubItem>

regards

Rajesh
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post what code you have done so far, or are you fishing for someone
to do your assignment for you?

Dave Patterson
 
Rajesh Rajaram
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
private static String getSubItemName(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();
NodeList nlist = elementpara.getElementsByTagName("HomogeneousMaterial");

System.out.println("nlist====" + nlist.getLength());
Element e1 =(Element)nlist.item(0);
String str = e1.getAttribute("name");
System.out.println("STR====" + str);

String sSubName = element.getAttribute("name");

System.out.println("sSubName====" + sSubName);

return returnStr;
}


public static void readingData(String fileName) throws Exception {
try{
initialize(fileName);
NodeList dbTag = doc.getElementsByTagName("MCD");
int detailLength = dbTag.getLength();
for (int j=0;j<detailLength;j++) {
Node firstDBTagNode = dbTag.item(j);
if (firstDBTagNode.getNodeType() == Node.ELEMENT_NODE){
Element firstDBTagElement = (Element) firstDBTagNode;

String str11 = getSubItemName(firstDBTagElement,"SubItem");
}
}
}catch(IOException io) {
System.out.println("====Exception===" + io.getMessage());
}
}

no fishing, got struck in the above method..

rgds

Rajesh
 
Rajesh Rajaram
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem here is the element <SubstanceCatagory> wont be the same with all the files i am parsing some case there might be two or three and in some case its possible like the above.

can anyone point me a hint for the above condition.

regards

Rajesh Rajaram
 
Rajesh Rajaram
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave,

Any updates for my code.

rgds

Rajesh Rajaram
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Rajesh.
By any chance r u from tambaram???!!!

thanks
 
I don't like that guy. The tiny ad agrees with me.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic