Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8300543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:35:54+00:00 2026-06-08T16:35:54+00:00

I was trying to parse a collada(.dae) file in java using plane DOM parser.

  • 0

I was trying to parse a collada(.dae) file in java using plane DOM parser. When I try to get value it returns me null. I tried with answers and suggestions from other discussions but was not a success. The code I used is below.

for(int k1=0;k1<meshlist.getLength();k1++) {
    Element geometryItr1 = (Element)geometrylist.item(k);

    NodeList trianglelist = geometryItr1.getElementsByTagName("triangles");

    //System.out.println("Triangles length is " + trianglelist.getLength());     

        for(int o=0;o<trianglelist.getLength();o++) {

            Element trichildnodes = (Element) trianglelist.item(o);
            NodeList inputs = trichildnodes.getElementsByTagName("input");
        NodeList p = trichildnodes.getElementsByTagName("p");
        Element ppp = (Element) p.item(0);
        System.out.println("Node Value " + ppp.getNodeValue());
        System.out.println(inputs.getLength() + "Input length");

        for(int in=0;in<inputs.getLength();in++) {

            Element inn = (Element) inputs.item(in);
            System.out.println(inn.getAttribute("semantic") + " " + inn.getAttribute("source") + " Attributes");

        }


        //System.out.println(p.getLength() +  " P's length" );
        //System.out.println("P's content " + ppp.getFirstChild().getNodeValue());


    }   
}

The XML is very large and I am posting a part which I was trying to parse.

<mesh>
  <source> </source>
  <source> </source>
  <source> </source>
  <triangles>
    <input />
    <input />
    <input />
    <p> 24 262 2 72 72 72 72 2222 8198219  </p>
  <triangles>
  <triangles>
    <input />
    <input />
    <input />
    <p> 24 262 2 72 72 72 72 2222 8198219  </p>
  <triangles>
  <triangles>
    <input />
    <input />
    <input />
    <p> 24 262 2 72 72 72 72 2222 8198219  </p>
  <triangles>
  <triangles>
    <input />
    <input />
    <input />
    <p> 24 262 2 72 72 72 72 2222 8198219  </p>
  <triangles>
</mesh>

I was trying to get the value of <p>. Everything works fine except getting p’s value. But when I debug I can see the values, its associated with first child. I even tried using firstChild. I am completely lost with parsing trying to find out a solution on this. Please some one help me find a solution on How to get the value of p ?

When I use getTextContent instead I get the output like below:

NodeValue null
NodeValue 24 262 2 72 72 72 72 2222 8198219
NodeValue null

The output is blank for two tags.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:35:55+00:00Added an answer on June 8, 2026 at 4:35 pm

    I would recommend using the javax.xml.xpath APIs available in the JDK/JRE since Java SE 5 to make the processing of your XML document easier:

    package forum11688757;
    
    import java.io.File;
    import javax.xml.parsers.*;
    import javax.xml.xpath.*;
    import org.w3c.dom.*;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document document = db.parse(new File("src/forum11688757/input.xml"));
    
            XPathFactory xpf = XPathFactory.newInstance();
            XPath xpath = xpf.newXPath();
            NodeList nodeList = (NodeList) xpath.evaluate("/mesh/triangles/p", document, XPathConstants.NODESET);
            for(int x=0; x<nodeList.getLength(); x++) {
                System.out.println(nodeList.item(x).getTextContent());
            }
        }
    
    }
    

    input.xml

    <mesh>
      <source> </source>
      <source> </source>
      <source> </source>
      <triangles>
        <input />
        <input />
        <input />
        <p> 24 262 2 72 72 72 72 2222 8198219  </p>
      </triangles>
      <triangles>
        <input />
        <input />
        <input />
        <p> 24 262 2 72 72 72 72 2222 8198219  </p>
      </triangles>
      <triangles>
        <input />
        <input />
        <input />
        <p> 24 262 2 72 72 72 72 2222 8198219  </p>
      </triangles>
      <triangles>
        <input />
        <input />
        <input />
        <p> 24 262 2 72 72 72 72 2222 8198219  </p>
      </triangles>
    </mesh>
    

    Output

     24 262 2 72 72 72 72 2222 8198219  
     24 262 2 72 72 72 72 2222 8198219  
     24 262 2 72 72 72 72 2222 8198219  
     24 262 2 72 72 72 72 2222 8198219  
    

    UPDATE

    You could also get the p elements using the following line of code. You need to be careful though since it will get all p elements not just those in the /mesh/triangles/p path

    NodeList nodeList = document.getElementsByTagName("p");
    

    The following approach will always get you the data you are looking for, even if p eleements are later added somewhere else in the document.

    NodeList nodeList = (NodeList) xpath.evaluate("/mesh/triangles/p", document, XPathConstants.NODESET);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse xml file and get no errors but when trying
Trying to parse and XLSX file using roo gem in a ruby script. In
Trying to parse out this xml file to get a list of Elements but
When trying to parse the following file, I get the error [10,4]: [ERR 101]
Whilst trying to parse MS Excel file using POI-HSSF v3.2 I am getting IndexOutOfBoundsException.
I'm trying to parse an INI file using C++. Any tips on what is
Trying to parse the following Python file using the lxml.etree.iterparse function. sampleoutput.xml <item> <title>Item
I trying to parse xml from an inputstream using the sax parser. The inputstream
I'm trying to parse a section of a large file with Java's Scanner library,
I'm trying parse the follow XML file: <root>Root <pai>Pai_1 <filho>Pai1,Filho1</filho> <filho>Pai1,Filho2</filho> </pai> <pai>Pai_2 <filho>Pai2,Filho1</filho>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.