Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within XML
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
XML and Related Technologies
Error in parsing XML
Siddharth Bhargava
Ranch Hand
Posts: 280
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Friends,
I am getting an error in validating an xml file using the schema. Following is the code snippet.
schemaValidation.xsd ------------------------- <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/schemaValidation" xmlns:tns="http://www.example.org/schemaValidation" elementFormDefault="qualified"/> <xsd:element name="fullname"> <xsd:complexType> <xsd:sequence> <xsd:element name="firstname" type="xsd:string"/> <xsd:element name="middlename" type="xsd:string"/> <xsd:element name="lastname" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> schema.xml -------------- <?xml version="1.0" encoding="UTF-8"?> <fullname xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation='schemaValidation.xsd'> <firstname>Sid</firstname> <middlename>S</middlename> <lastname>Bhargava</lastname> </fullname> Document doc; static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; public static void main(String[] args) { XMLValidationUsingSchema schema = new XMLValidationUsingSchema(); schema.validateXMLFile(); } private void validateXMLFile(){ //get the factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); try{ //Using factory get an instance of document builder DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(this); //parse using builder to get DOM representation of the XML file doc = builder.parse(new File("schema.xml")); } catch(ParserConfigurationException pce){ pce.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void error(SAXParseException e){ System.out.println("Error Parsing the file :: "+e.getMessage()); } public void warning(SAXParseException e){ System.out.println("Problem parsing the file :: "+e.getMessage()); } public void fatalError(SAXParseException e){ System.out.println("Error parsing the file :: "+e.getMessage()); System.out.println("Cannot continue ..."); System.exit(1); }
The exception which is coming is :
The prefix "xsd" for element "xsd:schema" is not bound.
Thanks and Regards,
Sid
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
xmlns="http://www.w3.org/2001/XMLSchema"
Isnt that supposed to be:
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
Bill
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
validation question od XML schemas
problem with validating sax parser
XML not getting validated with schema... + strange...
Axis2 - Transfer document using MTOM
Axis2 - Transfer document using MTOM
More...