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 7416327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:28:29+00:00 2026-05-29T07:28:29+00:00

I am using w3c DOM api in java . When I first parse my

  • 0

I am using w3c DOM api in java . When I first parse my XML from an input stream and use dom.getElementById("nodeId") method , it works . But If I update my dom with some node element having ID attributes , and then tries to retrieve this node using dom.getElementById("ID"), then it doesn’t work and return null.
Any Idea ?

Thanks.

  • 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-05-29T07:28:30+00:00Added an answer on May 29, 2026 at 7:28 am

    In fact the JavaDoc says something along the lines that getElementById returns the Element that has an ID attribute with the given value. An attribute with the name “ID” or “id” is not of type ID unless it is so defined.

    How is an attribute defined as an ID attribute? With a DTD or schema. If you are not validating the XML, then the API is useless.

    So, what to do if you want to find an element for which the attribute named “id” has a given value? Several options were offered in GetElementById Pitfalls. One of them is to use an XPath expression like this:"//*[@id = 'myId']".

    Also, in the Apache XML Security project, the class org.apache.xml.security.utils.IdResolver was specifically created to address this problem. Calling IdResolver.getElementById(doc, id) will return the element you are looking for.

    referhttp://www.xinotes.org/notes/note/738/

    here is an example to achieve it Java: How to make getElementById() work using xml schema

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using rpxnow in Java, how do I use org.w3c.dom API to get
I am parsing a XML file in Java using the W3C DOM. I am
i am using org.w3c.dom in java to read an xml with the following function
I can copy a node from one XML file to another using org.w3c.dom.Document. importNode(Node
I'm using org.w3c XML API to open an existing XML file. I'm removing some
I am using the URLUTF8Encoder.java class from W3C ( www.w3.org/International/URLUTF8Encoder.java ). Currently, it will
I am doing a lot of XML parsing/transformation using the org.w3c.dom classes. A Document
I am getting object of type org.w3c.dom.Document from a source (basically a parsed xml
I want to convert an java string containing xml to a w3c dom document
I am using org.w3c.dom.Element for adding elements to a xml file. Problem here is

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.