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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:43:29+00:00 2026-06-13T21:43:29+00:00

I know how to parse XML documents with DOM when they are in the

  • 0

I know how to parse XML documents with DOM when they are in the form:

<tagname> valueIWant </tagname>

However, the element I’m now trying to get is instead in the form

<photo farm="9" id="8147664661" isfamily="0" isfriend="0" ispublic="1" 
       owner="8437609@N04" secret="4902a217af" server="8192" title="Rainbow"/>

I usually use cel.getTextContent() to return the value, but that doesn’t work in this case. Neither does cel.getAttributes(), which I thought would work…

Ideally, I need to just get the id and owner numerical values. However if someone can help on how to get all of it, then I can deal with removing the parts I don’t want later.

  • 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-13T21:43:31+00:00Added an answer on June 13, 2026 at 9:43 pm

    What you’re looking to retrieve is the value of different attributes that are attached with an Element. Look at using the getAttribute(String name) method to achieve this

    If you want to retrieve all the attributes, all you can do so using getAttributes() and iterate through it. An example of both of these methods might be something like this:

    private void getData(Document document){
        if(document == null)
            return;
    
        NodeList list = document.getElementsByTagName("photo");
        Element photoElement = null;
    
        if(list.getLength() > 0){
            photoElement = (Element) list.item(0);
        }
    
        if(photoElement != null){
            System.out.println("ID: "+photoElement.getAttribute("id"));
            System.out.println("Owner: "+photoElement.getAttribute("owner"));
    
            NamedNodeMap childList = photoElement.getAttributes();
            Attr attribute;
    
            for(int index = 0; index < childList.getLength(); index++){
                if(childList.item(index).getNodeType() == Node.ATTRIBUTE_NODE){
                    attribute = ((Attr)childList.item(index));
                    System.out.println(attribute.getNodeName()+" : "+attribute.getNodeValue());
                }else{
                    System.out.println(childList.item(index).getNodeType());
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know a Perl library that can parse XML documents and enables me
I am trying to use DOM Parser in Java to parse a small XML
I'm trying to parse some of my first XML documents in SAX by simply
I am trying to parse somewhat standard XML documents that use a schema called
I want to know whether I can parse the 2 different xml documents in
Now i know to use the method of float.Parse but have bumped into a
I'm trying to parse Xml in Blackberry. I copied the xml to the SD
I'm attempting to parse xml containing foreign letters (æøå specifically), however I'm having problems
I'm trying to parse an XML document on Android 2.3.3, but it seems that
me again, sorry :) I was using dom parser to get xml from web

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.