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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:33:32+00:00 2026-06-18T14:33:32+00:00

I’d like to perform XPath queries on an XML document online. I’ve set up

  • 0

I’d like to perform XPath queries on an XML document online. I’ve set up InputStreams that retrieve the content and append a <?xml ...?> header that declares the encoding present in charset field of the HTTP requests. Although it works, it’s painfully slow.

    //bis is the BufferedInputStream with the content part of the HTTP reply
docBuilder = docBuilderFactory.newDocumentBuilder(); // throws exception.
Document doc = docBuilder.parse
    (new PrependInputStream(bis,
                "<?xml version='1.0' encoding='"+charset+"' ?>\r\n"));

(please allow me not to put my whole source this time: I’m preparing an assignment for students).

Some strace analysis revealed that the program stalls when contacting w3.org:

 send(8, "GET /TR/xhtml1/DTD/xhtml1-transitional.dtd HTTP/1.1\r\nUser-Agent: Java/1.6.0_17\r\nHost: www.w3.org\r\nAccept: 
      text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\nConnection: keep-alive\r\n\r\n", 186, 0)
 recv(8, ...

As I don’t worry too much about the HTML content to be valid (well-formed should be enough), I tried docBuilderFactory.setValidating(false) but that doesn’t seem to prevent online retrieval of the DTD.

Trying to set manually a schema with docBuilderFactory.setSchema() using the same dtd file retrieved manually results in a “org.xml.sax.SAXParseException: The markup in the document preceding the root element must be well-formed. ” (that was not a good idea)

Where am I over-complicating things?

(the XML backend seems to be com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema, as far as I can tell from stack traces — if that’s of any use).

  • 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-18T14:33:33+00:00Added an answer on June 18, 2026 at 2:33 pm

    HTML dtd’s are huge, using includes. And you are right, they take forever. Use an XML catalog. There one can store the dtds locally and map them by their system ID.

    If you use a tool, like maven, you will find sufficient pointers.

    The advantage i.o. intercepting entities as the answer linked by @sylvainulg suggests, is that you receive the correct characters.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I have a small JavaScript validation script that validates inputs based on Regex. I
I would like to run a str_replace or preg_replace which looks for certain words

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.