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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:18:22+00:00 2026-06-01T09:18:22+00:00

I am using BaseX native XML database to query XML files. I am using

  • 0

I am using BaseX native XML database to query XML files.
I am using the BaseXClient.java file provided in the BaseX documentation. I am starting the basex server and connecting to server using BaseXClient.java.

// create session
final BaseXClient session = new BaseXClient("localhost", 1984, "admin", "admin");

String query = "doc('xmlfiles/juicers.xml')//image";
// version 1: perform command and print returned string
System.out.println(session.execute(query));

Now the juicers.xml file has xmlns information.

<?xml version="1.0"?>
<juicers
xmlns="http://www.juicers.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.juicers.org 
                    juicers.xsd">

<juicer>
    <name>OJ Home Juicer</name>
    <image>images\mighty_oj.gif</image>
    <description>There&apos;s just no substitute for a properly squeezed
        orange in the morning. So delicate and refreshing. The finest hotels
        use mechanical juicers of this type for their most discriminating
        guests. This is the largest selling juicer of its kind. It&apos;s a
        beautiful little all-metal piece in baked enamel and polished chrome;
        it even won the Frankfurt Fair Award for its design. Uses no
        electricity and produces no non-recyclable waste as do frozen juices.
    </description>
    <warranty>lifetime warranty</warranty>
    <cost>41.95</cost>
    <retailer>http://www.thewhitewhale.com/oj.htm</retailer>
</juicer>
</juicers>

If I don’t give the xmlns in XML instance file (juicers.xml), it returns me correct results.
But if xmlns is included in XML instance file, the following exception is thrown.

java.io.IOException: Stopped at line 1, column 3:
Expecting command.
at org.basex.api.BaseXClient.execute(BaseXClient.java:73)
at org.basex.api.BaseXClient.execute(BaseXClient.java:84)
at org.basex.api.Example.main(Example.java:31)

How do I query XML instances files with xmlns? Is there a way out? Is there any other way to run xquery from Java?

  • 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-01T09:18:24+00:00Added an answer on June 1, 2026 at 9:18 am

    In addition to Chrstian’s answer, you have to either declare a default element namespace or use the namespace each time you address an element (you probably want to do this if you’d have multiple namespaces in your document).

    The default element namespace enables you to write your query like you did above:

    declare default element namespace "http://www.juicers.org";
    doc('xmlfiles/juicers.xml')//image
    

    If you do not want to use juicers as default element namespace, declare it as namespace and reference it at element-level:

    declare namespace juicers="http://www.juicers.org";
    doc('xmlfiles/juicers.xml')//juicers:image
    

    You can set the namespace identifier juicers arbitrarily.

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

Sidebar

Related Questions

I have been using this exact Build.xml file. I had problems in the beginning
I am working on a J2EE application, to deploy I am using a build.xml
I'm trying start java application but in browser i see standard tomcat's page. Server
I'm using ubuntu 9.10 and I installed java and tomcat using the package manager.
I downloaded tomcat 6, changed the port on server.xml to 8040 and started tomcat.
I have a WTP project in eclipse that is using Tomcat7 as server, everything
Is there a way to use my SOAP web service(spring-ws, java) as a XML
I am using JNI to wrap a few native functions in a closed-source PDF
I mainly develop in native C++ on Windows using Visual Studio. A lot of
I am working on iPhone app development currently (primarily native app using Obj-C and

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.