Many thanks. It worked.

 

We will test on wide variety of input xml files, and with satisfactory performance and error handling, we will purchase the license.

 

Thanks again

Jawahar

 

From: Michael Kay [mailto:mike@saxonica.com]
Sent: 23 June 2010 10:05
To: saxon-help@lists.sourceforge.net
Subject: Re: [saxon] Validating XML document using remote XSD and Saxon.Net 9.2

 

Another question occurred to me here: does the schema document that you are trying to read have any xs:include, xs:import, or xs:redefine declarations? It's possible that retrieval of the original document works using the credentials supplied, but retrieval of a referenced document is failing because there are no credentials.

If that turns out to be the case, then setting an XmlResolver on the Processor object might turn out to be a solution.

Michael Kay
Saxonica

On 22/06/2010 14:14, Mariappan, Jawahar Kaliraj wrote:

Hi,

I am trying to validate a XML document using remote XSD and saxon.Net 9.2. Though the credentials to access the remote server is set, the SchemaManager.Compile(XmlReader) is returning the following error message: net.sf.saxon.type.SchemaException: net.sf.saxon.trans.XPathException: javax.xml.transform.TransformerException: The remote server returned an error: (401) Unauthorized.

The C# code snippet is given below. For info, Saxon API is registered on the GAC and the Saxon home directory has been set. At the moment, I am using evaluation version. On successful validation and with satisfactory performance, I would like to buy the licensed version.

Please help.

Thanks

Jawahar

Processor processor = new Processor(true);

      SchemaManager manager = processor.SchemaManager;

      manager.ErrorList = new ArrayList();

      XmlReaderSettings schemaReaderSettings = new XmlReaderSettings();

      XmlUrlResolver resolver = new XmlUrlResolver();

      resolver.Credentials = new NetworkCredential(<UserName to access the remote server>,<Password to access the remote server>);

      schemaReaderSettings.XmlResolver = resolver;

      XmlReader schemaReader = XmlReader.Create(<remote http path to xsd file>, schemaReaderSettings);

     

      try

      {

        // Note: Visual studio debug watch indicates that the instance schemaReader.Settings.XmlResolve.Credentials is Null,

// though valid schemaReaderSettings is set in create statement.

manager.Compile(schemaReader);     

}

      catch (Exception e)

      {

        Console.WriteLine(e);

        Console.WriteLine("Schema compilation failed with " + manager.ErrorList.Count + " errors");

        foreach (StaticError error in manager.ErrorList)

        {

          Console.WriteLine("At line " + error.LineNumber + ": " + error.Message);

        }

        Console.ReadLine();

        return;

      }

 

      // Use this to validate an instance document

      SchemaValidator validator = manager.NewSchemaValidator();

      Uri instanceUri = new Uri(<Local source xml file to validate>);

      validator.SetSource(instanceUri);

      validator.ErrorList = new ArrayList();

      XdmDestination psvi = new XdmDestination();

      validator.SetDestination(psvi);

      try

      {

        validator.Run();

      }

      catch (Exception e)

      {

        Console.WriteLine(e);

        Console.WriteLine("Instance validation failed with " + validator.ErrorList.Count + " errors");

        foreach (StaticError error in validator.ErrorList)

        {

          Console.WriteLine("At line " + error.LineNumber + ": " + error.Message);

        }

        return;

      }

***********************************************************************************************

This email, including any attachment, is confidential and may be legally privileged. If you are not the intended recipient or if you have received this email in error, please inform the sender immediately by reply and delete all copies from your system. Do not retain, copy, disclose, distribute or otherwise use any of its contents.

 

Whilst we have taken reasonable precautions to ensure that this email has been swept for computer viruses, we cannot guarantee that this email does not contain such material and we therefore advise you to carry out your own virus checks. We do not accept liability for any damage or losses sustained as a result of such material.

 

Please note that incoming and outgoing email communications passing through our IT systems may be monitored and/or intercepted by us solely to determine whether the content is business related and compliant with company standards.

***********************************************************************************************

The Stationery Office Limited is registered in England No. 3049649 at 10 Eastbourne Terrace, London, W2 6LG

 

 
 
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
 
 
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help 



________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________