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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:00:33+00:00 2026-05-20T16:00:33+00:00

I have translated the following Javascript code to Java. The problem occurs at sib;

  • 0

I have translated the following Javascript code to Java. The problem occurs at sib;
http://snippets.dzone.com/posts/show/3754

I have never seen such for statements. What does it do exactly when you add a semicolon? Is this like while() statement?

 public static String getElementXpath(DOMElement elt){
        String path = ""; 
        for (;elt.ELEMENT_NODE == elt.getNodeType(); elt = (DOMElement) elt.getParentNode()){
            int idx = getElementIdx(elt);
        }
        return path;        
    }

    private static int getElementIdx(DOMElement elt) {
        int count = 1;

         for (DOMElement sib = (DOMElement) elt.getPreviousSibling(); sib ; sib = (DOMElement) sib.getPreviousSibling())
            {
                if(sib.ELEMENT_NODE == sib.getNodeType() && sib.getTagName() == elt.getTagName()) count++;
            }

        return count;
    }
  • 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-20T16:00:34+00:00Added an answer on May 20, 2026 at 4:00 pm

    If you meant the first for loop:

    for (;elt.ELEMENT_NODE == elt.getNodeType(); elt = (DOMElement) elt.getParentNode())
    

    then the initial ; indicates that there is no initialisation to be done.

    A normal for loop is: for (initialise; expression; update) so your one only has the expression and update parts. There is no need for initialisation in your case because the DOMElement is passed in as a parameter and doesn’t require any other steps before you use it in the for loop


    In response to comment:

    Before each iteration of the loop the test elt.ELEMENT_NODE == elt.getNodeType() is performed. This tests that the node referenced by elt is an element node (i.e. not a text node, attribute node, comment node etc). If the test fails then the body of the loop is executed.

    In the body of the loop, getElementIdx is called to calcuate the relative position of this node amongst any siblings of the same name. This value is stored in idx but nothing is done with it and the value is then discarded.

    After the body of the loop is executed, the update elt = (DOMElement) elt.getParentNode() is performed. This changes elt to reference the parent node of the node it previously referenced.

    As a first step, I would change elt.ELEMENT_NODE == elt.getNodeType() to Node.DOCUMENT_NODE == elt.getNodeType() (see comment from Paŭlo Ebermann below) as this will cause your program to work back through the parent nodes until it finds the root of the document

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

Sidebar

Related Questions

I have translated the following code using ternary. However, I knew there was something
I have the following problem. I have C code that acquires a PNG image
I have following code: <div class='no_translate'>Not translated</div> And following code for mouseover/mouseout events: $('.no_translate').mouseover(function()
I have the following inequalities on 21 variables: http://pastebin.com/raw.php?i=FTU970Em When I run Reduce[ineq,Integers] on
I have a code that need to be translated from C to Cpp, and
Im having a problem with the HeaderText not being translated when i have definied
I have to translate some code from C# to Java and I have the
I have the following code which tries to combine a vertical mirrored image with
I have the following code: return this.ObjectContext.BranchCostDetails.Where( b => b.TarrifId == tariffId && b.Diameter
i have written the following code var resumeedit=(from t in db.Resumes where t.User.UserID==theUserID &&

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.