Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > validation problem

Reply
Thread Tools

validation problem

 
 
sk
Guest
Posts: n/a
 
      07-04-2006
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().newDocumentBu ilder();
Document document = parser.parse(new File("c:\\myxmldoc.xml"));

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

SchemaFactory.newInstance(javax.xml.XMLConstants.W 3C_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 xmlnss="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>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Validation Problem...Persisiting form fields on validation failure. bnp Javascript 4 05-12-2004 12:16 PM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM
Web form validation vs object validation Colin Basterfield ASP .Net 1 11-29-2003 12:10 AM
validation summary doesnt display when there's client-side validation Libs ASP .Net 0 06-25-2003 03:05 PM
Re: only custom validation control does server side validation? Colin Mackay ASP .Net 0 06-25-2003 07:54 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57