hervens 0 Newbie Poster

Hello, I have the current sample xml document below:

<Units>
  <category name="Temp">
    <unit id="0">
      <unit_name>celcius</unit_name>
      <fromFormula>inFrom0</fromFormula> <-- need this value
      <toFormula>inTo0</toFormula>
    </unit>
    <unit id="1">
      <unit_name>fahrenheit</unit_name>
      <fromFormula>inFrom1</fromFormula>
      <toFormula>inTo1</toFormula>
    </unit>
  </category>
  <category name="Length">
    <unit id="0">
      <unit_name>feet</unit_name>
      <fromFormula>InLengthFrom</fromFormula>
      <toFormula>inLenghTo</toFormula>
    </unit>
  </category>
</Units>

Now, I am trying to retrieve the value "inFrom0" from the <fromFormula> element but Its not working
this is part of the code that I have so far

Element rootElement = document.getDocumentElement(); 
            System.out.println("works here" );
            rootElement.normalize();
            Node temp = rootElement.getElementsByTagName("category").item(0); 
            System.out.println("works here1 " + temp.getNodeName() + temp.getAttributes().getNamedItem("name").getNodeValue() );
            Node id = temp.getChildNodes().item(0);

            System.out.println("works here2 " + id.getNodeName() ); // <--returns #text instead of element!
            Node txt = id.getChildNodes().item(0); // <-- execution stops here
            System.out.println("works here3 " + txt.getNodeName());
            String result = txt.getChildNodes().item(0).getNodeValue();
            
            System.out.println("node value is: " + txt);

For some reason, right after
<category name="Temp"> my code cannot seem to reach the next xml element., and instead only sees an empty text node

The results from all the System.out.println are as followed:
works here
works here1 categoryTemp
works here2 #text

Thank you
Any help is appreciated

Also, if it helps, i'm using java and the blackberry sdk api

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.