Question about XML validation against schema
My question is probably a basic one about XML. I tried PurchaseOrder example from the book "J2EE Web Services" by Richard Monson-Haefel. A simplified version as followings -
Address.xsd -
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/Address"
xmlns:addr="http://xml.netbeans.org/schema/Address"
elementFormDefault="qualified">
<element name="address" type="addr:USAddress" />
<complexType name="USAddress">
<sequence>
<element name="name" type="string" />
<element name="street" type="string" />
<element name="city" type="string" />
<element name="state" type="string" />
<element name="zip" type="string" />
</sequence>
</complexType>
</schema>
PurchaseOrder.xsd -
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/PurchaseOrder"
xmlns:po="http://xml.netbeans.org/schema/PurchaseOrder"
xmlns:ad="http://xml.netbeans.org/schema/Address"
elementFormDefault="qualified">
<import namespace="http://xml.netbeans.org/schema/Address" schemaLocation="Address.xsd" />
<element name="purchaseOrder" type="po:PurchaseOrder" />
<complexType name="PurchaseOrder">
<sequence>
<element name="accountName" type="string" />
<element name="accountNumber" type="unsignedShort" />
<element name="shipAddress" type="ad:USAddress" />
<element name="total" type="float" />
</sequence>
<attribute name="orderDate" type="date" />
</complexType>
</schema>
Then PurchaseOrder.xml is -
<purchaseOrder orderDate="2007-12-12"
xmlns='http://xml.netbeans.org/schema/PurchaseOrder'
xmlns:addr="http://xml.netbeans.org/schema/Address"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://xml.netbeans.org/schema/PurchaseOrder ../xsd/PurchaseOrder.xsd'>
<accountName>Starwood</accountName>
<accountNumber>220</accountNumber>
<shipAddress>
<name>Data Center</name>
<street>1501 Washington St.</street>
<city>Braintree</city>
<state>MA</state>
<zip>02148</zip>
</shipAddress>
<total>250</total>
</purchaseOrder>
Then I did a XML validation but have this error -
cvc-complex-type.2.4.a: Invalid content was found starting with element 'name'. One of '{"http://xml.netbeans.org/schema/Address":name}' is expected. [19]
It complains <name> tag in <shipAddrss> needs namespace of "http://xml.netbeans.org/schema/Address". Why?
Is it possible to change XML so it does not need name space for elements inside <shipAddress>?
Thanks
Hi Madhura,
see here my comparison of the web version against the local file version on my Windows box (which is itself not the fastest): It makes a factor 16 in difference!
C:\Temp\xsdvalidator>java XsdValidator madhu.xsd madhu.xml
cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
NOK - Validation error
Elapsed time: 16353 ms
C:\Temp\xsdvalidator>java XsdValidator madhu_local.xsd madhu.xml
cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
NOK - Validation error
Elapsed time: 994 ms
Obviously, the w3c.org domain that you specified as ressource location is very slow - and, as the FAQ shows, this delay is intentional!
The W3C servers are slow to return DTDs. Is the delay intentional?
Yes. Due to various software systems downloading DTDs from our site millions of times a day (despite the caching directives of our servers), we have started to serve DTDs and schema (DTD, XSD, ENT, MOD, etc.) from our site with an artificial delay. Our goals in doing so are to bring more attention to our ongoing issues with excessive DTD traffic, and to protect the stability and response time of the rest of our site. We recommend HTTP caching or catalog files to improve performance.
--> They don't want to have requests to their site from productive servers all around the world.
Regards,
Rüdiger
Similar Messages
-
XML validation against schema in XSD format
I have a requirement for validation of XML file against XML schema(XSD format). Using IXML liabrary I know how to validate XML file against schema in DTD format. But i am not getting how to do it against XSD. Is it possible using IXML liabrary? Also i wanted to know how to attach one XML or CSV file into another XML file using SAP ABAP.
Please provide solution!!Hi Madhura,
see here my comparison of the web version against the local file version on my Windows box (which is itself not the fastest): It makes a factor 16 in difference!
C:\Temp\xsdvalidator>java XsdValidator madhu.xsd madhu.xml
cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
NOK - Validation error
Elapsed time: 16353 ms
C:\Temp\xsdvalidator>java XsdValidator madhu_local.xsd madhu.xml
cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
NOK - Validation error
Elapsed time: 994 ms
Obviously, the w3c.org domain that you specified as ressource location is very slow - and, as the FAQ shows, this delay is intentional!
The W3C servers are slow to return DTDs. Is the delay intentional?
Yes. Due to various software systems downloading DTDs from our site millions of times a day (despite the caching directives of our servers), we have started to serve DTDs and schema (DTD, XSD, ENT, MOD, etc.) from our site with an artificial delay. Our goals in doing so are to bring more attention to our ongoing issues with excessive DTD traffic, and to protect the stability and response time of the rest of our site. We recommend HTTP caching or catalog files to improve performance.
--> They don't want to have requests to their site from productive servers all around the world.
Regards,
Rüdiger -
Hi,
We have SAP WebAS 6.20. Can someone help me understand how I can validate XML document against schema in ABAP.
Thanks,
Sumanhi
u can check the below links
XML schema in ABAP
Can i use XSD / XML in Abap Programs
Regards,
Naveen -
XML validation against schema (NOT DTD)
Hi,
I am fairly new at parsing XML documents, but I am trying to parse
an XML document using the Xerces SAXParser.
I can parse my xml document, no problems there, but I want to validate
it against an xml schema file, without specifying the file in the xml document.
How can I do this? If I set validating to true, it gives me errors about a DTD,
but I don't have a DTD, I want to use a schema file.
Can anybody help me, or give me a code example?
THanks,
SvenSAXParser parser = new SAXParser();
parser.setFeature("http://xml.org/sax/features/validation",
true);
parser.setFeature("http://apache.org/xml/features/validation/schema",
true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
true); -
Problem in xml validation against schema
this is the xml file
<?xml version="1.0" encoding="UTF-8"?><hello xmlns=""><Capabilities xmlns=""><capability xmlns="">base</capability><capability xmlns="">writablerunning</capability><capability xmlns="">null</capability><username xmlns="">netconf</username><password xmlns="">netconf</password></Capabilities></hello>
xsd file is
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:com.tel.netconf.server"
xmlns="urn:com.tel.netconf.server"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="hello" type="helloType"/>
<xs:element name="username" type="xs:string"/>
<xs:element name="password" type="xs:string"/>
<xs:element name="Capabilities" type="capabilitiesinfo"/>
<xs:complexType name="capabilitiesinfo">
<xs:sequence>
<xs:element name="capability" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="username"/>
<xs:element ref="password"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="helloType>
<xs:sequence>
<xs:element ref="Capabilities"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
error msg is
Error: Document is invalid: no grammar found.
at line 2, column 7
in entity file:///D:/NETCONF/axis-src-1_4/axis/netconf/com/tel/netconf/server/h
ello1.xml
Error: Document root element "hello", must match DOCTYPE root "null".
at line 2, column 7 in entity file:///D:/NETCONF/axis-src-1_4/axis/netconf/com/tel/netconf/server/h
ello1.xml
org.xml.sax.SAXParseException: The value of attribute "name" associated with an
element type "xs:complexType" must not contain the '<' character.
plz kindly help me outHi Madhura,
see here my comparison of the web version against the local file version on my Windows box (which is itself not the fastest): It makes a factor 16 in difference!
C:\Temp\xsdvalidator>java XsdValidator madhu.xsd madhu.xml
cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
NOK - Validation error
Elapsed time: 16353 ms
C:\Temp\xsdvalidator>java XsdValidator madhu_local.xsd madhu.xml
cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
NOK - Validation error
Elapsed time: 994 ms
Obviously, the w3c.org domain that you specified as ressource location is very slow - and, as the FAQ shows, this delay is intentional!
The W3C servers are slow to return DTDs. Is the delay intentional?
Yes. Due to various software systems downloading DTDs from our site millions of times a day (despite the caching directives of our servers), we have started to serve DTDs and schema (DTD, XSD, ENT, MOD, etc.) from our site with an artificial delay. Our goals in doing so are to bring more attention to our ongoing issues with excessive DTD traffic, and to protect the stability and response time of the rest of our site. We recommend HTTP caching or catalog files to improve performance.
--> They don't want to have requests to their site from productive servers all around the world.
Regards,
Rüdiger -
Hi,
Does Oracle 8i (Release 3) support XML validations against XSD? I know Oracle 9i (Release 2) supports XML validations against XSD.
Also, Does Oracle support XML validations against XDR?
Any info is appreciated.
Thanks
PavanValidate with DOMParser or the SAXParser.
-
QUESTION: XML validation against a schema - for beginners
Hi folks,
i am new to XML validation.
i would like to find out how to validate an XML file using a schema given to me by a third part company.
the business process requires that our company sends a weekly file which complies with their schema.
in real-life, i am expecting some details of our file to fail against their schema.
thus i would like to find a way validating the file localy before sending it to this third part.
this validation would ideally allow me to highlight and identify which records are failing the validation, and enable me to strip those and send only those that are successfully checked.
on the example below, i would expect to have the record for John Smith to be successful (country has an integer); while Queen Victoria would fail as it uses UK instead of an integer to identify the country.
thus i would need to find a way validating this XML file, move the record of Queen Victoria to another file to be fixed and to allow, the record for John Smith to be sent out.
if you guys could post some links to where i can find further information on this type of processing, i would be most grateful.
Many thanks,
Nicolas
using an example from:
[http://www.codeguru.com/csharp/csharp/cs_data/xml/article.php/c6737]
XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="address">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="city"type="xs:string"/>
*<xs:element name="country"type="xs:integer"/>*
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>XML
<address>
<name>John Smith</name>
<street>109 Abbey Close</street>
<city>Hayes</city>
<country>98</country>
</address>
<address>
<name>Queen Victoria</name>
<street>1 Regent Street</street>
<city>London</city>
<country>UK</country>
</address>Edited by: www.jegue.net on Jan 13, 2009 9:48 AM
Edited by: www.jegue.net on Jan 13, 2009 9:49 AMi would need to find a way validating this XML file, move the record of Queen Victoria to another file to be fixed and to allow, the record for John Smith to be sent out.I don't think any automated tool or API available with such features. You should achieve this by some tricky logic/code.
-
In-memonry xml document validation against schema with xerces
Hello, there.
I found that I can't use JAXP's javax.xml.validation package with jdk 1.4. (Am I wrong?)
Anyway,
I found that I can use xerces's DOMParser for the same purpose.
But I can't find the way to validate my programmatically generate org.w3c.dom.Document against existing schema file.
Can anybody help me?
Thanks.Have you read Xerces documentation or SUN xml API, there is always a parser option (I suppose it's in the standard) to validate input while parsing.
Look the API : http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setValidating(boolean) -
Validating xml input against schema's registered in database
Hi,
We have an application that stores a massive XSD document (with cyclical references between schemas) in a VARCHAR2 column of a table. The XSD is loaded everytime an xml input needs to be parsed. The problem is that the XSD is very huge, and maintaining it is going to be a problem as it continues to grow. I don't beleieve this is the most efficient way of doing this.
What I would like to do is to register each of the schemas that are part of the large XSD and use the <include schemaLocation/> directive. I have seen tutorials for doing this. Example tutorial at this link:
http://www.cs.utah.edu/classes/cs5530/oracle/doc/B10501_01/appdev.920/a96620/xdb05obj.htm
My sole purpose for registering the XSD's is to validate any xml input that is passed in as input to my Java program that is running in the database; I don't want to store the input xml in a table. If the input is successfully validated, my program will continue processing.
I have seen some Java OTN tutorials which have methods with 2 parameters - xml, and xsd. I want to avoid this approach because in my case, the XSD would already be registered in the database.
Any tips would be very much appreciated.
Cheers,
RudiAN XML Document may be validated with schema registered in database.
http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10790/xdb08tra.htm#sthref843 -
Using XSL on XML validated against XSD
Transforming XSD validated XMLType Data
Re: example XSL in Chapter 6 that transforms XML with associated XSD schema definition (Oracle 9i XML Database Developer's Guide)
I noted that this XSL uses only the "general" node identification functions (e.g., name() ) to access nodes in the <xsl:value-of select..>. I have also noted that standard XSL templates from other sections of the documentation, for example in Chapter 3 and in Appendix D, do not work with an XML which is validated against an XSD schema.
Can anyone give me an example <xsl:value-of select..> that addresses a specific node in the "purchase order" example, like the shipTo, name, street -- or any other specific node. This is critical since there is always bound to be node-specific processing in any transformation, and this is not demonstrated by any example of XML which has been validated against an XSD.
I have tried this endlessly on my own examples of XML w/XSD validation. Even if the value-of select="name(.)" tells you that the name of the node is "FooBar", you cannot use FooBar as a select test to do FooBar specific processing.
Help?????Not quite understand your question. Can you send me the example doc?
-
XSL used on XML validated against XSD
Transforming XSD validated XMLType Data
Re: example XSL in Chapter 6 that transforms XML with associated XSD schema definition (Oracle 9i XML Database Developer's Guide)
I noted that this XSL uses only the "general" node identification functions (e.g., name() ) to access nodes in the <xsl:value-of select..>. I have also noted that standard XSL templates from other sections of the documentation, for example in Chapter 3 and in Appendix D, do not work with an XML which is validated against an XSD schema.
Can anyone give me an example <xsl:value-of select..> that addresses a specific node in the "purchase order" example, like the shipTo, name, street -- or any other specific node. This is critical since there is always bound to be node-specific processing in any transformation, and this is not demonstrated by any example of XML which has been validated against an XSD.
I have tried this endlessly on my own examples of XML w/XSD validation. Even if the value-of select="name(.)" tells you that the name of the node is "FooBar", you cannot use FooBar as a select test to do FooBar specific processing.
Help?????Not quite understand your question. Can you send me the example doc?
-
XML validation against DTD.. Is it possible?
Hello all,
Sorry for what may be a trivial post, but I'll keep it short..
According to the docs:
"The Validate XML command will validate the XML against the schema defined in the XML file. This command on the context menu is disabled whenever an XML file does not have an XML namespace defined."
I'm used to the XML editor retrieving a DTD from somewhere and validating it against that.. is it possible to do this in JDev?Unfortunately it's not. We only have support for validating against XML Schemas.
Rob -
Hi,
I have an application that receives XML from an external source. The XML received does not have the XML version and the doc type declaration lines. I want to validate the XML against a DTD.
One dirty way of doing this is to open the XML received and prepend the XML versions and doctype lines to it. And then parse the XML. But is it the right way to do it?
What I would like to know is that does the XML parser provide any API which can tell it to validate an XML document against a certain DTD.Yes, there is an API to do this. You have to do something like this:
DocumentBuilderFactory dbf =DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
DocumentBuilder db = dbf.newDocumentBuilder();
XMLErrors eh = new XMLErrors(frame);
db.setErrorHandler(eh);
Document doc = db.parse(f);
(where f is the XML file)
In this example, the class XMLErrors is used as the ErrorHandler. XMLErrors extends the DefaultHandler class and provides the user with information about the various error levels. A call to the over-ridden "error" method notifies the user (using a Dialog box) that the document doesn't meet the DTD.
Hope this helps. -
Question about using Sun Multi-Schema XML Validator
Hi all,
I tried to use sun MSV to validate xml against my schema file, the result turns strange. To simply test the validator, I use the following xml file and xsd file:
------- test.xml -------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<persons xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<person>1</person>
<person>2</person>
<person>3</person>
</persons>
--------test.xsd ---------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="persons">
<xs:complexType>
<xs:sequence>
<xs:element name="person" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
In my knowledge of xml schema, the above xml file should be validated "ok" against the xsd files.
But in sun msv validator, it reports the following error:
------------ error message ---------------------------------------------------
Error of test.xml
element "person" was found where no element may occur
Why does this happen? I have defined the occurrence of "person" element under "persons" to unbounded. What is the possible wrong?
Thanks in advance!Problem sovled by updating the msv lib files. Thx for noticing!
-
Validating against schema file for the output XML file
Hi,
I am using XSLT for mapping. The output message is generated according to the mappings but it is not validate aganist schema of target . I am using xsd file from external defination section as target. Can any body help me in this regard.
Thanks,
Mallikarjun.Mhi,
if you talk about the schema of a target message type
than validation only works if you use graphical
message mapping
not with: xslt,java, abap
Regards,
michal
<a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions">XI FAQ - Frequently Asked Questions</a>
Maybe you are looking for
-
Oracle BPM 12c: getting error while opening of bpm project in bpm composer
Hi, I am importing bpm project into bpm composer from jdeveloper using PAM and export/import utility but I am not able to open it into the bpm composer. I am getting following error: javax.faces.el.EvaluationException: java.lang.NullPointerException
-
Where can i get a rubber feet replacement for my Macbook pro 13 inch case?
I need some ruber feet replacment for my mac case?
-
Is now the time to buy FCP?
I own the original Final Cut Studio. I just bought a new Mac Pro eight core. I'm considering the latest version but don't know if the timing is right. When was the last time FCP was updated? Buy now or wait? The upgrade from FCP Studio is $499 from A
-
Hi We are trying to view the list of Parked documents using FBV0/FBV1. But it gives just the list of parked documents. To view the details, a document should be selected and double clicked. Is there any transaction where we can get list of parked doc
-
My laptop crashed with mine and my husbands I tunes Library. I have sync my i phone with my work mac but I am still missing some of my songs. My husband was unable to do this as his i phone broke too and he has no music at all. Please help.