Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


validation problem

From: "sk" <s@-.--->
To: NULL
Date: 7/4/2006 5:42:00 PM

I am trying to make validation program but getting the following error.

org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of
element 'tag1'.

I attached the xml document and schema as well as the java program to
validate the xml doc.



//java program to validate the xml document
DocumentBuilder parser =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(new File("c:\\myxmldoc.xml"));

// Create a SchemaFactory capable of understanding WXS schemas.
SchemaFactory factory =

SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);

// Load a WXS schema, represented by a Schema instance.
javax.xml.transform.Source schemaFile = new
javax.xml.transform.stream.StreamSource(new File("c:\\XMLType2.xsd"));
Schema schema = factory.newSchema(schemaFile);

// Create a Validator object, which can be used to validate
Validator validator = schema.newValidator();

// Validate the DOM tree.
validator.validate(new javax.xml.transform.dom.DOMSource(document));

//xml document////////
<?xml version="1.0"?>
<tag1 >
hello world
</tag1>

//schema///////////////////
<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="tag1">
<xs:simpleType>
<xs:restriction base="xs:string" >
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent