You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Lex <gr...@homerlex.mailshell.com> on 2002/10/10 17:07:19 UTC

noNamespaceSchemaLocation - Specifying on the Server side

Here is the sceanrio:

 

Using xerces parser on the server side.

 

HTML clients post some XML to the server and the server validates.  This
is

requiring the cients to specify the noNamespaceSchemaLocation in the xml

they are sending to the server.  The server in turn uses this to
validate

the XML - which might look like this:

 

<?xml version="1.0" encoding="UTF-8"?>

<Message

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:noNamespaceSchemaLocation="http://someserver/validate.xsd"

    >

    <Request MessageType="QUERY">

      <CustomerNames="All"/>

      <CustomerLocations="All"/>

    </Request >

</Message>

 

This requires the client to specify a location of the xsd that the
server

has access to.  I would rather have the client provide the same XML
wothout

the noNamespaceSchemaLocation and have the server decide where to look
for

it.

 

Aside from preparsing in the noNamespaceSchemaLocation before validating
is

there any other way in my server code to just tell the xerces parser to
look

for the file at a specified location?

 

Regards


Re: Can't get the sample socket example to work (KeepSocketOpen)

Posted by Andy Clark <an...@apache.org>.
Roger L. Costello wrote:
> Note: changing the port number in KeepSocketOpen.java made no
> difference.

Hmmm... How is your machine configured? You should
have some ports open. You may want to change the
code in the sample to add a loop that tries to
create the server with different port numbers and
then create the client with the port number that
actually succeeded.

-- 
Andy Clark * andyc@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Can't get the sample socket example to work (KeepSocketOpen)

Posted by "Roger L. Costello" <co...@mitre.org>.
Hi Folks,

In the xerces-2_2_0 samples subfolder is a "socket" example.  I am
unable to get it to run.  I get an "Address in Use" exception.  Below is
the full error message.  Any ideas on what the problem is and how to
resolve it?  /Roger

Here is the error message:

Exception in thread "main" java.net.BindException: Address in use:
JVM_Bind
        at java.net.PlainSocketImpl.socketBind(Native Method)
        at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:405)
        at java.net.ServerSocket.<init>(ServerSocket.java:170)
        at java.net.ServerSocket.<init>(ServerSocket.java:82)
        at socket.KeepSocketOpen$Server.<init>(Unknown Source)
        at socket.KeepSocketOpen$Server.<init>(Unknown Source)
        at socket.KeepSocketOpen.main(Unknown Source)

Note: changing the port number in KeepSocketOpen.java made no
difference.


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Can't get Andy Clark's sample Entity Resolver to work

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
This is a known bug in Xerces, long since fixed. You need to upgrade to
a recent version of Xerces.

Searching bugzilla for "EntityResolver" will display the relevant
item(s).

Regards

Simon

On Fri, 2002-10-11 at 05:59, Roger L. Costello wrote:
> Hi Folks,
> 
> I recently purchased a book [1] in which Andy Clark has a section on
> using an Entity Resolver to override the System ID in a DOCTYPE
> declaration.  I have had problems getting his code to work.
> 
> Here is the Entity Resolver that I copied from Andy's book:
> 
> public class SimpleEntityResolver
>     implements EntityResolver {
> 
>     public InputSource resolveEntity(String publicId, String systemId)
>         throws SAXException, IOException {
>         System.out.println("systemId = " + systemId);        
>         // resolve known entity using system identifier
>         if (systemId.equals("http://www.xfront.com/BookCatalogue.dtd"))
> {
>             // open local file
>             InputStream inputStream = 
>                      new FileInputStream("c:\\BookCatalogue.dtd");    
>     
>             // create input source and return
>             InputSource inputSource = new InputSource(inputStream);
>             inputSource.setPublicId(publicId);
>             inputSource.setSystemId(systemId);
>             return inputSource;
>         }
>         
>         // don't know how to resolve entity, let parser resolve it
>         return null;
>     
>     }
> 
> Notice the output statement that I inserted, to output the value of the
> systemId parameter.  It always outputs a value of null (why?)  Here is
> the XML document that I can using:
> 
> <?xml version="1.0"?>
> <!DOCTYPE BookCatalogue SYSTEM
> "http://www.xfront.com/BookCatalogue.dtd">
> <BookCatalogue>
>         <Book>
>                 <Title>My Life and Times</Title>
>                 <Author>Paul McCartney</Author>
>                 <ISBN>94303-12021-43892</ISBN>
>                 <Publisher>McMillin Publishing</Publisher>
>                 <Date>July, 1998</Date>
>         </Book> 
>         ...
> </BookCatalogue>
> 
> Oddly, when I modified the Entity Resolver to not do the if-test on the
> systemId, then it worked fine.  That is, here is the modified Entity
> Resolver:
> 
> public class SimpleEntityResolver
>     implements EntityResolver {
> 
>     public InputSource resolveEntity(String publicId, String systemId)
>         throws SAXException, IOException {
>             // open local file
>             InputStream inputStream = 
>                      new FileInputStream("c:\\BookCatalogue.dtd");    
>     
>             // create input source and return
>             InputSource inputSource = new InputSource(inputStream);
>             inputSource.setPublicId(publicId);
>             inputSource.setSystemId(systemId);
>             return inputSource;
>     }
> 
> This version works fine.  Can someone tell me why the systemId is always
> null when this method is fired?
> 
> For completeness, here is the SAX parser code that I am using:
> 
>     public static String process(String xmlFileURL) {
>         try {
>             validate validate = new validate();
>             XMLReader parser = 
>                 XMLReaderFactory.createXMLReader(parserName);
>             EntityResolver entityResolver = new SimpleEntityResolver();
>             parser.setEntityResolver(entityResolver);
>             parser.setContentHandler(validate);
>             parser.setErrorHandler(validate);
>             parser.setFeature("http://xml.org/sax/features/validation",
> true);
>             parser.parse(xmlFileURL);
>             return validate.result.toString(); 
>         }
>         catch (Exception e) { e.printStackTrace(); }
>         return null;
> 
> Any help would be much appreciated.  /Roger
> 
> [1] XML and Java, Second Edition, Developing Web Applications
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Can't get Andy Clark's sample Entity Resolver to work

Posted by "Roger L. Costello" <co...@mitre.org>.
Hi Folks,

I recently purchased a book [1] in which Andy Clark has a section on
using an Entity Resolver to override the System ID in a DOCTYPE
declaration.  I have had problems getting his code to work.

Here is the Entity Resolver that I copied from Andy's book:

public class SimpleEntityResolver
    implements EntityResolver {

    public InputSource resolveEntity(String publicId, String systemId)
        throws SAXException, IOException {
        System.out.println("systemId = " + systemId);        
        // resolve known entity using system identifier
        if (systemId.equals("http://www.xfront.com/BookCatalogue.dtd"))
{
            // open local file
            InputStream inputStream = 
                     new FileInputStream("c:\\BookCatalogue.dtd");    
    
            // create input source and return
            InputSource inputSource = new InputSource(inputStream);
            inputSource.setPublicId(publicId);
            inputSource.setSystemId(systemId);
            return inputSource;
        }
        
        // don't know how to resolve entity, let parser resolve it
        return null;
    
    }

Notice the output statement that I inserted, to output the value of the
systemId parameter.  It always outputs a value of null (why?)  Here is
the XML document that I can using:

<?xml version="1.0"?>
<!DOCTYPE BookCatalogue SYSTEM
"http://www.xfront.com/BookCatalogue.dtd">
<BookCatalogue>
        <Book>
                <Title>My Life and Times</Title>
                <Author>Paul McCartney</Author>
                <ISBN>94303-12021-43892</ISBN>
                <Publisher>McMillin Publishing</Publisher>
                <Date>July, 1998</Date>
        </Book> 
        ...
</BookCatalogue>

Oddly, when I modified the Entity Resolver to not do the if-test on the
systemId, then it worked fine.  That is, here is the modified Entity
Resolver:

public class SimpleEntityResolver
    implements EntityResolver {

    public InputSource resolveEntity(String publicId, String systemId)
        throws SAXException, IOException {
            // open local file
            InputStream inputStream = 
                     new FileInputStream("c:\\BookCatalogue.dtd");    
    
            // create input source and return
            InputSource inputSource = new InputSource(inputStream);
            inputSource.setPublicId(publicId);
            inputSource.setSystemId(systemId);
            return inputSource;
    }

This version works fine.  Can someone tell me why the systemId is always
null when this method is fired?

For completeness, here is the SAX parser code that I am using:

    public static String process(String xmlFileURL) {
        try {
            validate validate = new validate();
            XMLReader parser = 
                XMLReaderFactory.createXMLReader(parserName);
            EntityResolver entityResolver = new SimpleEntityResolver();
            parser.setEntityResolver(entityResolver);
            parser.setContentHandler(validate);
            parser.setErrorHandler(validate);
            parser.setFeature("http://xml.org/sax/features/validation",
true);
            parser.parse(xmlFileURL);
            return validate.result.toString(); 
        }
        catch (Exception e) { e.printStackTrace(); }
        return null;

Any help would be much appreciated.  /Roger

[1] XML and Java, Second Edition, Developing Web Applications


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org