You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Celinio Fernandes <cf...@pagesjaunes.fr> on 2005/08/01 15:19:59 UTC

Validate an XML file against a schema

Hi,

How do you specify the name and location of the Schema file .xsd against
which the validate() method will validate the XML file ?

In the following example, where/how do you specify the name / location
of the schema .xsd file ?

 // Create an XmlOptions instance and set the error listener.
 XmlOptions validateOptions = new XmlOptions();
 ArrayList errorList = new ArrayList();
 validateOptions.setErrorListener(errorList);
 
 // Validate the XML.
 boolean isValid = newEmp.validate(validateOptions);
 
 // If the XML isn't valid, loop through the listener's contents,
 // printing contained messages.
 if (!isValid)
 {
      for (int i = 0; i < errorList.size(); i++)
      {
          XmlError error = (XmlError)errorList.get(i);
          
          System.out.println("\n");
          System.out.println("Message: " + error.getMessage() + "\n");
          System.out.println("Location of invalid XML: " + 
              error.getCursorLocation().xmlText() + "\n");
      }
 }

Thanks


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


Re: RE : Validate an XML file against a schema

Posted by Brian Bonner <br...@paraware.com>.
You're correct.

Brian



Celinio Fernandes wrote:

>I think I got it wrong, I should spend more time reading the API before
>posting a question.
>
> boolean isValid = newEmp.validate(validateOptions); 
>==> validates the XML file against the schema.
>
>Can anyone quickly confirm this please ?
>
>Sorry,
>Thanks
>
>
>-----Message d'origine-----
>De : Celinio Fernandes [mailto:cfernandes.externe@pagesjaunes.fr] 
>Envoyé : lundi 1 août 2005 15:20
>À : user@xmlbeans.apache.org
>Objet : Validate an XML file against a schema
>
>
>Hi,
>
>How do you specify the name and location of the Schema file .xsd against
>which the validate() method will validate the XML file ?
>
>In the following example, where/how do you specify the name / location
>of the schema .xsd file ?
>
> // Create an XmlOptions instance and set the error listener.
>XmlOptions validateOptions = new XmlOptions();  ArrayList errorList =
>new ArrayList();  validateOptions.setErrorListener(errorList);
> 
> // Validate the XML.
> boolean isValid = newEmp.validate(validateOptions);
> 
> // If the XML isn't valid, loop through the listener's contents,  //
>printing contained messages.  if (!isValid)  {
>      for (int i = 0; i < errorList.size(); i++)
>      {
>          XmlError error = (XmlError)errorList.get(i);
>          
>          System.out.println("\n");
>          System.out.println("Message: " + error.getMessage() + "\n");
>          System.out.println("Location of invalid XML: " + 
>              error.getCursorLocation().xmlText() + "\n");
>      }
> }
>
>Thanks
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>  
>

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


RE : Validate an XML file against a schema

Posted by Celinio Fernandes <cf...@pagesjaunes.fr>.
I think I got it wrong, I should spend more time reading the API before
posting a question.

 boolean isValid = newEmp.validate(validateOptions); 
==> validates the XML file against the schema.

Can anyone quickly confirm this please ?

Sorry,
Thanks


-----Message d'origine-----
De : Celinio Fernandes [mailto:cfernandes.externe@pagesjaunes.fr] 
Envoyé : lundi 1 août 2005 15:20
À : user@xmlbeans.apache.org
Objet : Validate an XML file against a schema


Hi,

How do you specify the name and location of the Schema file .xsd against
which the validate() method will validate the XML file ?

In the following example, where/how do you specify the name / location
of the schema .xsd file ?

 // Create an XmlOptions instance and set the error listener.
XmlOptions validateOptions = new XmlOptions();  ArrayList errorList =
new ArrayList();  validateOptions.setErrorListener(errorList);
 
 // Validate the XML.
 boolean isValid = newEmp.validate(validateOptions);
 
 // If the XML isn't valid, loop through the listener's contents,  //
printing contained messages.  if (!isValid)  {
      for (int i = 0; i < errorList.size(); i++)
      {
          XmlError error = (XmlError)errorList.get(i);
          
          System.out.println("\n");
          System.out.println("Message: " + error.getMessage() + "\n");
          System.out.println("Location of invalid XML: " + 
              error.getCursorLocation().xmlText() + "\n");
      }
 }

Thanks


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


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