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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:00:00+00:00 2026-05-14T22:00:00+00:00

I’m trying to read XML file, ex : <entry> <title>FEED TITLE</title> <id>5467sdad98787ad3149878sasda</id> <tempi type="application/xml">

  • 0

I’m trying to read XML file, ex :

<entry>
    <title>FEED TITLE</title>
    <id>5467sdad98787ad3149878sasda</id>
    <tempi type="application/xml">
      <conento xmlns="http://mydomainname.com/xsd/radiofeed.xsd" madeIn="USA" />
    </tempi>
</entry>

Here is the code I have so far: http://pastebin.com/huKP4KED

Here is what I need, concerning XML above:

  • I need to get value of title, id
  • attribute value of tempi as well as madeIn attribute value of contento

What is the best way to do this ?

Edit

@Pascal Thivent

Maybe creating method would be good idea like public String getValue(String xml, Element elementname), where you specify tag name, the method returns tag value or tag attribute (maybe give it name as additional method argument) if the value is not available

What I really want to get certain tag value or attribute if tag value(s) is not available, so I’m in the process of thinking what is the best way to do so since I’ve never done it before.

  • 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-14T22:00:01+00:00Added an answer on May 14, 2026 at 10:00 pm

    The best solution for this is to use XPath. Let’s say we have the following feed.xml file:

    <?xml version="1.0" encoding="UTF-8" ?>
    <entries>
    <entry>
        <title>FEED TITLE 1</title>
        <id>id1</id>
        <tempi type="type1">
          <conento xmlns="dontcare?" madeIn="MadeIn1" />
        </tempi>
    </entry>
    <entry>
        <title>FEED TITLE 2</title>
        <id>id2</id>
        <tempi type="type2">
          <conento xmlns="dontcare?" madeIn="MadeIn2" />
        </tempi>
    </entry>
    <entry>
        <id>id3</id>
    </entry>
    </entries>
    

    Here’s a short but compile-and-runnable proof-of-concept (with feed.xml file in the same directory).

    import javax.xml.xpath.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import java.io.*;
    import java.util.*;
    
    public class XPathTest {
        static class Entry {
            final String title, id, origin, type;
            Entry(String title, String id, String origin, String type) {
                this.title = title;
                this.id = id;
                this.origin = origin;
                this.type = type;
            }
            @Override public String toString() {
                return String.format("%s:%s(%s)[%s]", id, title, origin, type);
            }
        }
    
        final static XPath xpath = XPathFactory.newInstance().newXPath();
        static String evalString(Node context, String path) throws XPathExpressionException {
            return (String) xpath.evaluate(path, context, XPathConstants.STRING);
        }
    
        public static void main(String[] args) throws Exception {
            File file = new File("feed.xml");
            Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
            NodeList entriesNodeList = (NodeList) xpath.evaluate("//entry", document, XPathConstants.NODESET);
    
            List<Entry> entries = new ArrayList<Entry>();
            for (int i = 0; i < entriesNodeList.getLength(); i++) {
                Node entryNode = entriesNodeList.item(i);
                entries.add(new Entry(
                    evalString(entryNode, "title"),
                    evalString(entryNode, "id"),
                    evalString(entryNode, "tempi/conento/@madeIn"),
                    evalString(entryNode, "tempi/@type")
                ));
            }
            for (Entry entry : entries) {
                System.out.println(entry);
            }
        }
    }
    

    This produces the following output:

    id1:FEED TITLE 1(MadeIn1)[type1]
    id2:FEED TITLE 2(MadeIn2)[type2]
    id3:()[]
    

    Note how using XPath makes the value retrieval very simple, intuitive, readable, and straightforward, and "missing" values are also gracefully handled.

    API links

    • package javax.xml.xpath
    • http://www.w3.org/TR/xpath
    • Wikipedia/XPath
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm parsing an XML file, the creators of it stuck in a bunch social
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.