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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:16:26+00:00 2026-05-27T18:16:26+00:00

I have an XML file of the following structure: <?xml version=1.0 encoding=utf-8?> <root> <ArrayOfLocationDTO

  • 0

I have an XML file of the following structure:

<?xml version="1.0" encoding="utf-8"?>
<root>
<ArrayOfLocationDTO xmlns:xsi="foo1" xmlns:xsd="foo2" xmlns="foo3">
<LocationDTO ~some data~>~child nodes etc~</LocationDTO>
<LocationDTO ~some data~>~child nodes etc~</LocationDTO>
... ... ...
<LocationDTO ~some data~>~child nodes etc~</LocationDTO>
<LocationDTO ~some data~>~child nodes etc~</LocationDTO>
</ArrayOfLocationDTO>
</root>

I’m trying to grab all ‘LocationDTO’ from there. My code looks like that:

XPath xpath = XPathFactory.newInstance().newXPath();
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
File XMLPath=new File(Environment.getExternalStorageDirectory(), "XMLSource.xml");
Document document = builder.parse(XMLPath);
NodeList nodes = (NodeList) xpath.evaluate("//LocationDTO", document, XPathConstants.NODESET);
int count=nodes.getLength();

My problem is that the code finds nothing unless I remove ‘ArrayOfLocationDTO’ manually from XML source.
Why ArrayOfLocationDTO prevents my code from working properly and how can I make it work without programmatical removal of ArrayOfLocationDTO (I consider the latter a sort of ‘dirty solution’)?

  • 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-27T18:16:28+00:00Added an answer on May 27, 2026 at 6:16 pm

    ArrayOfLocationDTO has an attribute xmlns=”foo3″. This attribute is one of the very few XML attributes that have a special meaning: specifically it means that ArrayOfLocationDTO and each tag inside it has a namespace “foo3” (each XML tag has a local name and – optionally – a namespace – which is a string introduced by one of xmlns syntaxes).

    This means that your document has NO tag of name “LocationDTO”. “LocationDTO” is only a local part of the name.

    You have two choices:

    • find tags by their local names, using function local-name: //*[local-name()=’LocationDTO’]; this is by far the quickest solution in your case (a simple search, small document, a single namespace)

    • establish a namespace context (using, if I remember correctly, setNamespaceContext) that binds “foo3” to an arbitrary prefix (eg. “f”) and use the query: //f:LocationDTO

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

Sidebar

Related Questions

I have xml file whose structure is defined with following xsd: <?xml version=1.0 encoding=utf-8?>
I have the following XML structure: <?xml version=1.0 encoding=utf-8?> <xml> <root> <Item> <taxids> <string>330</string>
I have the following XML file: <xml version=1.0 encoding=utf-8?> <Data> <Parameter1>1</Parameter1> </Data> I want
I have the following xml structure : <?xml version=1.0 encoding=utf-8 ?> <nws> <url>http://cpa.hypotheses.org/feed</url> <url>http://news.ycombinator.com/rss</url>
I have this XML structure: <?xml version=1.0 encoding=utf-8?> <Request> <RequestHeader requestType=CreateUserRequest dateTime=2011-08-01T16:50:25.9387377+10:00 /> <RequestBody>
I have an XML file with the following structure: <root> <subroot id=someID> <val1 value=a/>
I have an XML file of the following structure <Root> <Child Name=First> <Data Name=a
I have a large xml file (approx. 10 MB) in following simple structure: <Errors>
If i have the following directory structure: Project1/bin/debug Project2/xml/file.xml I am trying to refer
I have an XML file in the following structure. <NewDataSet> <markers> <name>name text</name> <desc>desc

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.