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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:11:47+00:00 2026-06-01T10:11:47+00:00

I am using StAX to process a XML file. The document has a DOCTYPE

  • 0

I am using StAX to process a XML file. The document has a DOCTYPE reference to a dtd file

<!DOCTYPE onlineDoc SYSTEM "onlineDoc.dtd">

I get the XML from the internet (am streaming it), and the DTD file lies just next to the XML (but – like the xml – on the remote machine).

Now the DTD contains some entity declarations, that are used in the XML i.e.

<!ENTITY Ntilde "&#209;" ><!-- capital N, tilde -->

I dont provide the DTD yet, so the StAX parser throws an exception saying that the entity Ntilde cannot be resolved.

Q: how do I provide the DTD file to the parser (it would be best, if it could be a stream from teh internet).

  • 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-01T10:11:49+00:00Added an answer on June 1, 2026 at 10:11 am

    With Woodstox everything’s fine. Here’s my snippet (using ClasspathResource class from Spring):

    XMLInputFactory xif = XMLInputFactory.newFactory();
    xif.setXMLResolver(new XMLResolver() {
      @Override
      public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException {
        try {
          if ("onlineDoc.dtd".equals(systemID))
            return new ClassPathResource(systemID, getClass()).getInputStream();
        }
        catch (IOException e) {
          return null;
        }
        return null;
      }
    });
    XMLStreamReader reader = xif.createXMLStreamReader(new ClassPathResource("a.xml", this.getClass()).getInputStream());
    while (reader.hasNext()) {
      reader.next();
      if (reader.isCharacters())
        log.info(new String(reader.getTextCharacters()));
    }
    

    it works and for:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <!DOCTYPE onlineDoc SYSTEM "onlineDoc.dtd">
    <onlineDoc>
        <test>a &Ntilde; b</test>
    </onlineDoc>
    

    prints:

    a Ñ b
    

    in Maven use:

    <dependency>
       <groupId>org.codehaus.woodstox</groupId>
       <artifactId>woodstox-core-asl</artifactId>
       <version>4.1.2</version>
    </dependency>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my program, I am using STAX Parser to parse an XML document
I am using StAX to construct an XML document using an XMLStreamWriter . However,
I'm using StAX in order to write an XML document but I can't find
I am using StAX to create a quite large xml document. Until now I
I am reading an XML file using Stax parser and writing it using DOM
this is my first time using StAX for parsing XML documents (still in the
I'm using XStream and JETTISON's Stax JSON serializer to send/receive messages to/from JSON javascripts
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
I am trying to write XML data using Stax where the content itself is
I am using the StAX Streaming Api in vrsion 1.2.0 from http://stax.codehaus.org/ . When

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.