Blatent error with Schema Validation Mode
I'm using the XDK v10 Beta and am having severe issues with what I consider to be the valid addition of a node and what the document considers to be valid.
If I use the XMLElement.canAppendChild() method, often false it returned even when it is allowable. If I ignore the results of this and use XMLElement.appendChild() method I am thrown a "DOM error 16" (bear in mind that DOM errors are on a scale of 0-15...).
oracle.xml.parser.v2.XMLDOMException: dom error 16 occurred
at oracle.xml.parser.v2.XMLNSNode.appendChild(XMLNSNode.java:509)
Can anybody let me know if this is a known issue - from my experience the only situation in which this does NOT occur is if you are appending a child element to the root of the document.
Thanks
Further to what I have written above, if I use:
XMLDocument.setContinuousValidityChecking(false);
XMLElement.appendChild(newChild);
XMLDocument.setContinuousValidityChecking(true);
System.out.println(XMLDocument.getContinuousValidityChecking());
I get the output true with no exceptions thrown.
This implies that the addition has not violated any validity checking rules, however without turning continousValidityChecking on and off I am informed that this addition is illegal.
If you need a more detailed test-case (albeit in whatever form) please let me know.
Thanks
Similar Messages
-
JAXP API provides no way to enable XML Schema validation mode
I am evaluating XDK 9.2.0.5.0 for Java and have encountered another
problem with XML Schema support when using the JAXP API.
Using the classes in oracle.xml.jaxp.*, it appears to be impossible to
enable XML Schema validation mode. I can set the schema object, but
the parser does not use it for validation.
If I use DOMParser directly, I can call the setValidationMode(int)
method to turn on schema validation mode. There is no equivalient
means to enable XML Schema validation when using the JAXP API.
Test case for JAXP API:
=== begin OracleJAXPSchemaTest.java ======
package dfranklin;
import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import oracle.xml.parser.schema.XMLSchema;
import oracle.xml.parser.schema.XSDBuilder;
import org.w3c.dom.*;
import org.xml.sax.*;
public class OracleJAXPSchemaTest
private final static String xsd = ""
+"<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"urn:dfranklin:test\">"
+" <xsd:element name=\"amount\" type=\"xsd:integer\"/>"
+"</xsd:schema>";
private final static String xml =
"<amount xmlns=\"urn:dfranklin:test\">1</amount>";
public static void main(String[] args)
throws Exception
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"oracle.xml.jaxp.JXDocumentBuilderFactory");
new OracleJAXPSchemaTest().run();
public void run()
throws Exception
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
dbf.setNamespaceAware(true);
XMLSchema xmlSchema = buildXMLSchema(new StringReader(xsd));
dbf.setAttribute("oracle.xml.parser.XMLParser.SchemaObject",
xmlSchema);
DocumentBuilder docbldr = dbf.newDocumentBuilder();
Document doc = docbldr.parse(new InputSource(new StringReader(xml)));
print(doc);
private XMLSchema buildXMLSchema(Reader xsdin)
throws Exception
XSDBuilder xsdBuilder = new XSDBuilder();
XMLSchema xmlSchema = (XMLSchema)xsdBuilder.build(xsdin, null);
return xmlSchema;
private void print(Document doc)
throws
javax.xml.transform.TransformerConfigurationException,
javax.xml.transform.TransformerException
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(new DOMSource(doc), new StreamResult(System.out));
System.out.println();
=== end OracleJAXPSchemaTest.java ======
Running that program:
java dfranklin.OracleJAXPSchemaTest
produces this output
Exception in thread "main" oracle.xml.parser.v2.XMLParseException: Element 'amount' used but not declared.
at oracle.xml.parser.v2.XMLError.flushErrors(XMLError.java:148)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:269)
at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:149)
at oracle.xml.jaxp.JXDocumentBuilder.parse(JXDocumentBuilder.java:96)
at dfranklin.OracleJAXPSchemaTest.run(OracleJAXPSchemaTest.java:40)
at dfranklin.OracleJAXPSchemaTest.main(OracleJAXPSchemaTest.java:27)
This shows that the parser is not using the XML Schema to validate the
document. I think it's expecting to find a DTD.
Here is the equivalent program using DOMParser directly, and setting
validation mode to SCHEMA_VALIDATION.
=== begin OracleParserTest.java ====
package dfranklin;
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import oracle.xml.parser.schema.XMLSchema;
import oracle.xml.parser.schema.XSDBuilder;
import oracle.xml.parser.v2.DOMParser;
import oracle.xml.parser.v2.XMLParser;
import org.w3c.dom.*;
import org.xml.sax.*;
public class OracleParserTest
private final static String xsd = ""
+"<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"urn:dfranklin:test\">"
+" <xsd:element name=\"amount\" type=\"xsd:integer\"/>"
+"</xsd:schema>";
private final static String xml =
"<amount xmlns=\"urn:dfranklin:test\">1</amount>";
public static void main(String[] args)
throws Exception
new OracleParserTest().run();
public void run()
throws Exception
DOMParser dp = new DOMParser();
XMLSchema xmlSchema = buildXMLSchema(new StringReader(xsd));
dp.setXMLSchema(xmlSchema);
dp.setValidationMode(XMLParser.SCHEMA_VALIDATION);
dp.parse(new InputSource(new StringReader(xml)));
Document doc = dp.getDocument();
print(doc);
private XMLSchema buildXMLSchema(Reader xsdin)
throws Exception
XSDBuilder xsdBuilder = new XSDBuilder();
XMLSchema xmlSchema = (XMLSchema)xsdBuilder.build(xsdin, null);
return xmlSchema;
private void print(Document doc)
throws
javax.xml.transform.TransformerConfigurationException,
javax.xml.transform.TransformerException
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.transform(new DOMSource(doc), new StreamResult(System.out));
System.out.println();
=== end OracleParserTest.java ====
Running that program
java dfranklin.OracleParserTest
produces this output
<?xml version = '1.0'?>
<amount xmlns="urn:dfranklin:test">1</amount>
In this case, the parser has validated the document.
I also tried this with version 10.1.0.0.0 beta, and got the same
error.
Darin FranklinThanks for posting that. I tried that code and still got my problem. The big difference is that I'm reading a group of XML files each of which uses a large number of schema files. There are over 50 schema files organized so they can be included as needed. Each of the XML files has a noNamespaceSchemaLocation attribute specifying one of the ten top schma files, that includes many others.
However, I did solve the problem. I added one line --
saxb.setFeature( "http://apache.org/xml/features/validation/schema",
true);
// next line is new
saxb.setProperty( JAXPConstants.JAXP_SCHEMA_LANGUAGE,
JAXPConstants.W3C_XML_SCHEMA );after the setFeature to turn on schema validation.
(It needs an import org.apache.xerces.jaxp.JAXPConstants; statement.)
Note:With the feature set to true and the setProperty commented out, the EntityResolver is called at construction tiem, and for each schema file, but each element is flagged as needing to be declared.
With the feature commented out, and the setProperty in place, the EntityResolver is not called, and there is no validation performed. (I added invalid content to one of the files and there were no errors listed.)
With both the setFeature and the setProperty in place, however, I get the calls from the EntityResolver indicating that it is processing the schema files, and for the good files, I get no errror, but for the bad file, I get an error indicating a bad validation.
Now I can make the EntityResolver quiet and get what I wanted. Maybe there are other ways to do this, but I've got one that works. :-)
Thanks to all who have helped.
Dave Patterson -
Persisting unexplained errors when parsing XML with schema validation
Hi,
I am trying to parse an XML file including XML schema validation. When I validate my .xml and .xsd in NetBeans 5.5 beta, I get not error. When I parse my XML in Java, I systematically get the following errors no matter what I try:
i) Document root element "SQL_STATEMENT_LIST", must match DOCTYPE root "null".
ii) Document is invalid: no grammar found.
The code I use is the following:
try {
Document document;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse( new File(PathToXml) );
My XML is:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Defining the SQL_STATEMENT_LIST element -->
<xs:element name="SQL_STATEMENT_LIST" type= "SQL_STATEMENT_ITEM"/>
<xs:complexType name="SQL_STATEMENT_ITEM">
<xs:sequence>
<xs:element name="SQL_SCRIPT" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<!-- Defining simple type ApplicationType with 3 possible values -->
<xs:simpleType name="ApplicationType">
<xs:restriction base="xs:string">
<xs:enumeration value="DawningStreams"/>
<xs:enumeration value="BaseResilience"/>
<xs:enumeration value="BackBone"/>
</xs:restriction>
</xs:simpleType>
<!-- Defining the SQL_SCRIPT element -->
<xs:element name="SQL_SCRIPT" type= "SQL_STATEMENT"/>
<xs:complexType name="SQL_STATEMENT">
<xs:sequence>
<xs:element name="NAME" type="xs:string"/>
<xs:element name="TYPE" type="xs:string"/>
<xs:element name="APPLICATION" type="ApplicationType"/>
<xs:element name="SCRIPT" type="xs:string"/>
<!-- Making sure the following element can occurs any number of times -->
<xs:element name="FOLLOWS" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
and my XML is:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : SQLStatements.xml
Created on : 1 juillet 2006, 15:08
Author : J�r�me Verstrynge
Description:
Purpose of the document follows.
-->
<SQL_STATEMENT_LIST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.dawningstreams.com/XML-Schemas/SQLStatements.xsd">
<SQL_SCRIPT>
<NAME>CREATE_PEERS_TABLE</NAME>
<TYPE>CREATION</TYPE>
<APPLICATION>DawningStreams</APPLICATION>
<SCRIPT>
CREATE CACHED TABLE PEERS (
PEER_ID VARCHAR(20) NOT NULL,
PEER_KNOWN_AS VARCHAR(30) DEFAULT ' ' ,
PRIMARY KEY ( PEER_ID )
</SCRIPT>
</SQL_SCRIPT>
<SQL_SCRIPT>
<NAME>CREATE_COMMUNITIES_TABLE</NAME>
<TYPE>CREATION</TYPE>
<APPLICATION>DawningStreams</APPLICATION>
<SCRIPT>
CREATE CACHED TABLE COMMUNITIES (
COMMUNITY_ID VARCHAR(20) NOT NULL,
COMMUNITY_KNOWN_AS VARCHAR(25) DEFAULT ' ',
PRIMARY KEY ( COMMUNITY_ID )
</SCRIPT>
</SQL_SCRIPT>
<SQL_SCRIPT>
<NAME>CREATE_COMMUNITY_MEMBERS_TABLE</NAME>
<TYPE>CREATION</TYPE>
<APPLICATION>DawningStreams</APPLICATION>
<SCRIPT>
CREATE CACHED TABLE COMMUNITY_MEMBERS (
COMMUNITY_ID VARCHAR(20) NOT NULL,
PEER_ID VARCHAR(20) NOT NULL,
PRIMARY KEY ( COMMUNITY_ID, PEER_ID )
</SCRIPT>
</SQL_SCRIPT>
<SQL_SCRIPT>
<NAME>DROP_PEER_TABLE</NAME>
<TYPE>DELETION</TYPE>
<APPLICATION>DawningStreams</APPLICATION>
<SCRIPT>
DROP TABLE PEERS IF EXISTS
</SCRIPT>
</SQL_SCRIPT>
<SQL_SCRIPT>
<NAME>DROP_COMMUNITIES_TABLE</NAME>
<TYPE>DELETION</TYPE>
<APPLICATION>DawningStreams</APPLICATION>
<SCRIPT>
DROP TABLE COMMUNITIES IF EXISTS
</SCRIPT>
</SQL_SCRIPT>
<SQL_SCRIPT>
<NAME>DROP_COMMUNITY_MEMBERS_TABLE</NAME>
<TYPE>DELETION</TYPE>
<APPLICATION>DawningStreams</APPLICATION>
<SCRIPT>
DROP TABLE COMMUNITY_MEMBERS IF EXISTS
</SCRIPT>
</SQL_SCRIPT>
<SQL_SCRIPT>
<NAME>CREATE_COMMUNITY_MEMBERS_VIEW</NAME>
<TYPE>CREATION</TYPE>
<APPLICATION>DawningStreams</APPLICATION>
<SCRIPT>
CREATE VIEW COMMUNITY_MEMBERS_VW AS
SELECT P.PEER_ID, P.PEER_KNOWN_AS, C.COMMUNITY_ID, C.COMMUNITY_KNOWN_AS
FROM PEERS P, COMMUNITIES C, COMMUNITY_MEMBERS CM
WHERE P.PEER_ID = CM.PEER_ID
AND C.COMMUNITY_ID = CM.COMMUNITY_ID
</SCRIPT>
<FOLLOWS>CREATE_PEERS_TABLE</FOLLOWS>
<FOLLOWS>CREATE_COMMUNITIES_TABLE</FOLLOWS>
</SQL_SCRIPT>
</SQL_STATEMENT_LIST>
Any ideas? Thanks !!!
J�r�me VerstryngeHi,
I found the solution in the following post:
Validate xml with DOM - no grammar found
Sep 17, 2003 10:58 AM
The solution is to add a line of code when parsing:
try {
Document document;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse( new File(PathToXml) );
The errors are gone !!!
J�r�me Verstrynge -
Error in schema validation in XI. Please help!
Hi Experts,
I have a FILE to proxy scenario. In the sender agreement I have selected schema validation by Adapter. (Other option is by Integration Engine). Now when the file I get an error in sender file communication channel monitoring:
Error: com.sap.engine.interfaces.messaging.api.exception.MessageFormatException: Schema DataIn.xsd not found in D:\usr\XXXXXXXXX\validation\schema\31f7c36098e411deadcae4d30a13c639\httptraining-00EIM_POC\DataIn_Async_Out\httptraining-00EIM_POC\DataIn.xsd (validation\schema)
Do I need to keep the schema file in some server location? Do I need to setup this path anywhere? Where do I need to place the schema file?
What is the difference between validation by adapter and by integration engine?
Please help!
Thanks
Gopal>What is the difference between validation by adapter and by integration engine?
Both are same. One in Java engine and the other in the abap engine. If you set at one place that is good enough. In 7.1+ this becomes one of the pipeline steps.
>Do I need to keep the schema file in some server location? Do I need to setup this path anywhere? Where do I need to place the schema file
Yes you have to place schema in the server location.
Refer the Rajasekar document for the placing this file in the server location. -
Test-spcontentdatabase error with claims authentictaion mode in sharepoint 2013
I know this has been come up before but could not find any good answer so reposting . I am following Microfoft guide for upgrading Sp 2010 to Sp2013. Existing SP2010 sites use claims based authentication. I made backup of existing content database from
SP2010 farm, copied them to SP2013 farm and restored on database server. Also created web applications on SP2013 farm also using claims based authentication from UI in Central Administration .
After that I used
Test-SPContentDatabase cmdlet in order to check restored SP2010 content database against SP2013 web application and i am getting error
Category : Configuration
Error : False
UpgradeBlocking : False
Message : The [SharePoint Primary - 443] web application is configured with claims authentication mode however the content database you are trying to attach is intended to be used against a windows classic authentication
mode.
Remedy : There is an inconsistency between the authentication mode of target web application and the source web application. Ensure that the authentication mode setting in upgraded web application is the
same as what you had in previous
SharePoint 2010 web application. Refer to the link "http://go.microsoft.com/fwlink/?LinkId=236865"
for more information.
Any idea on how to resolve and why am i getting this error ?
Thanks
MP
mpNow at this point you can just attach the database to either web application and notice that it will still upgrade. If you want run the ps command:
convert-spwebapplication -identity
http://nameofyourwebapp -to claims -retainpermissions
which will update the
web app and the users. After that check the web application user policy for verification. Make sure to add the
spsuperreader and
spsuperuser accounts too. I had some issues where I had to re enter the site collection owners in CA and the site collection.
If you're getting a constant pop up for credentials I would check to make sure that the sites are "trusted" in IE through group policy and set it up with a wildcard (*) to cover all sites. Ex:
http://*.yourdomainname.com
Jennifer Knight (MCITP, MCPD)
Thanks Jennifer - I ran into the same situation and agree with you this must be a bug. Seeing
others having similar issue as well. Not seeing any response from Microsoft on this yet.
BlueSky2010
Please help and appreciate others by using forum features: "Propose As Answer", "Vote As Helpful" and
"Mark As Answer" -
Possible to use SAX2 with schema validation
I am trying to wade through various options on validation.
Is it possible with the Oracle schema validation code to use SAX2 as the underlying parser? The example code with the 9.0 XDK uses DOM.Yes, you don't have to use DOM parser.
DOM is only needed for validating Identity constraints that require the tree. -
Batching 837P error with extended validation
I am batching a 837P (multiple) using BizTalk 2010. If I enable Extended validation in the agreement the batched message fails the send pipeline for the following 'Error details: Unable to read the stream produced by the pipeline. Details:
There was no XML start tag open' From the looks of it the message has the following BOM (EF BB BF). Upon emoving the Extended validation the batched 837 is created by the send port.
Path;
Receive file -> map to 837p -> write to folder using edi send (linked to party) -> edi receive with batching flag -> edi batching -> release batch -> write to final locationr using edi send (linked to party, filter to batched message)
With extended validation the initial 837p before batching are created just fine.
Any help would be greatly appreciated.
Thanks
TomWriting the unbatched 837s seemed to be the easiest option to add batching to the solution. And we have other batching applications that follow the same (820)
Thanks -
Hi,
I have an infopath web brower enabled form. In the form i have a date field.
I am passing the data from the database to that field using the C# code.
But, as the field from database is coming as string, i am getting an error, and i am not able to assign the value.
I get the date value from database as "3/25/2011 12:00:00 AM"
I used the below code:
[CODE]
if (objInfopathFormcData.myRecievedDate != null)
myRoot.SelectSingleNode("/my:myFields/my:field97", NamespaceManager).SetValue(objInfopathFormcData.myRecievedDate);
[/CODE]
I am getting the error as "Schema validation found non-data type errors".
How to set the value for a date field in Infopath.
Thank youHI,
I fixed it:
Below code is used to fix:
[CODE]
XPathNavigator xfield = null;
DateTime dtmyRecievedDate;
dtmyRecievedDate = Convert.ToDateTime(objInfopathFormcData.myRecievedDate);
if (objFormcData.FcCompletionDate != null)
xfield = myRoot.SelectSingleNode("/my:myFields/my:field97", NamespaceManager);
DeleteNil(xfield);
xfield.SetValue(dtmyRecievedDate.GetDateTimeFormats().GetValue(5).ToString());
// method to delete xsi:nil
private void DeleteNil(XPathNavigator nav1)
if (nav1.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
nav1.DeleteSelf();
[/CODE]
Thank you -
Hi!
A am parsing XML using JAXP 1.3. If i parse my XML with schema validation, i got an exception: org.xml.sax.SAXParseException: http://www.w3.org/TR/xml-schema-1#cvc-type.3.1.1?g_start&xsi:nil at line: 48 column: 27.
XML line: 48:
<g_start xsi:nil="true"></g_start>Schema for this element:
<xsd:element name="g_start" type="xsd:date" minOccurs="0" nillable="true"/>If i validate my XML with XMLSpy, it's OK.
Is it problem in my XML, or something wrong with JAXP?i wonder what happens if you use
<g_start xsi:nil="true"/>Nothing changes.
I make some small sample, if your wold like to test it.
<?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="elem" type="xsd:boolean" minOccurs="0" nillable="true"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<elem xsi:nil="true"></elem>
</root>
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(new File("schema.xsd"));
DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
documentFactory.setSchema(schema);
DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder();
Document document = documentBuilder.parse(new File("data.xml")); -
SAX Parser Validation with Schemas (C, C++ and JAVA)
We are currently using the Oracle XML Parser for C to parse and validate XML data using the SAX parser interface with validation turned on. We currently define our XML with a DTD, but would like to switch to schemas. However, the Oracle XML Parser 9.2.0.3.0 (C) only validates against a DTD, not a schema when using the SAX interface. Are there plans to add schema validation as an option? If so, when would this be available? Also, the same limitation appears to be true for C++ and JAVA. When will any of these provide SAX parsing with schema validation?
Thanks!
JohnWill get back to you after checked with development team...
-
Hi All
How to tackle this xml schema validation problem
i am using the sample code provided by ORacle technet for xml
schema validation in the Oracle database(817).
The sample code works perfectly fine.
Sample as provided by http://otn.oracle.com/tech/xml/xdk_sample/archive/xdksample_093001.zip.
It works fine for normal xml files validated against
xml schema (xsd)
but in this case my validation is failing . Can you let me know why
I have this main schema
Comany.xsd
===========
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns="http://www.company.org"
elementFormDefault="qualified">
<xsd:include schemaLocation="Person.xsd"/>
<xsd:include schemaLocation="Product.xsd"/>
<xsd:element name="Company">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Person" type="PersonType" maxOccurs="unbounded"/>
<xsd:element name="Product" type="ProductType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
================
which includes the following 2 schemas
Product.xsd
============
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:complexType name="ProductType">
<xsd:sequence>
<xsd:element name="Type" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
==============
Person.xsd
===========
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="SSN" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
=================
now when i try to validate a xml file against Company.xsd
it throws an error saying unable to find Person.xsd.
no protocol error
Now where do i place these 2 schemas(.xsd files) Person & product
so that the java schemavalidation program running inside Oracle
database can locate these files
Rgrds
SushantHi Jinyu
This is the java code loaded in the database using loadjava called by a wrapper oracle stored procedure
import oracle.xml.parser.schema.*;
import oracle.xml.parser.v2.*;
import java.net.*;
import java.io.*;
import org.w3c.dom.*;
import java.util.*;
import oracle.sql.CHAR;
import java.sql.SQLException;
public class SchemaUtil
public static String validation(CHAR xml, CHAR xsd)
throws Exception
//Build Schema Object
XSDBuilder builder = new XSDBuilder();
byte [] docbytes = xsd.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(docbytes);
XMLSchema schemadoc = (XMLSchema)builder.build(in,null);
//Parse the input XML document with Schema Validation
docbytes = xml.getBytes();
in = new ByteArrayInputStream(docbytes);
DOMParser dp = new DOMParser();
// Set Schema Object for Validation
dp.setXMLSchema(schemadoc);
dp.setValidationMode(XMLParser.SCHEMA_VALIDATION);
dp.setPreserveWhitespace (true);
StringWriter sw = new StringWriter();
dp.setErrorStream (new PrintWriter(sw));
try
dp.parse (in);
sw.write("The input XML parsed without errors.\n");
catch (XMLParseException pe)
sw.write("Parser Exception: " + pe.getMessage());
catch (Exception e)
sw.write("NonParserException: " + e.getMessage());
return sw.toString();
This is the code i used initially for validating a xml file against single xml schema (.xsd) file
In the above code could u tell how to specify the second schema validation code for the incoming xml.
say i create another Schemadoc for the 2nd xml schema.
something like this with another parameter(CHAR xsd1) passing to the method
byte [] docbytes1 = xsd1.getBytes();
ByteArrayInputStream in1 = new ByteArrayInputStream(docbytes1);
XMLSchema schemadoc1 = (XMLSchema)builder.build(in1,null);
DOMParser dp = new DOMParser();
How to set for the 2nd xml schema validation in the above code or can i combine 2 xml schemas.
How to go about it
Rgrds
Sushant -
Xdksample_093001.zip - Schema Validation example
I have downloaded this example and installed it as per
instructions.
when I try to run it I get the following error.
The following error has occurred:
ORA-29532: Java call terminated by uncaught Java exception:
oracle.xml.parser.schema.XSDException: Element 'schema' has
invalid namespace: 'http://www.w3.org/2001/XMLSchema'
ORA-06512: at "NM31.SCHEMAUTIL", line 0
ORA-06512: at line 15
Details:
ORA-29532: Java call terminated by uncaught Java exception:
oracle.xml.parser.schema.XSDException: Element 'schema' has
invalid namespace: 'http://www.w3.org/2001/XMLSchema'
ORA-06512: at "NM31.SCHEMAUTIL", line 0
ORA-06512: at line 15
How do I/Can I resolve this?Hi Jinyu
This is the java code loaded in the database using loadjava called by a wrapper oracle stored procedure
import oracle.xml.parser.schema.*;
import oracle.xml.parser.v2.*;
import java.net.*;
import java.io.*;
import org.w3c.dom.*;
import java.util.*;
import oracle.sql.CHAR;
import java.sql.SQLException;
public class SchemaUtil
public static String validation(CHAR xml, CHAR xsd)
throws Exception
//Build Schema Object
XSDBuilder builder = new XSDBuilder();
byte [] docbytes = xsd.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(docbytes);
XMLSchema schemadoc = (XMLSchema)builder.build(in,null);
//Parse the input XML document with Schema Validation
docbytes = xml.getBytes();
in = new ByteArrayInputStream(docbytes);
DOMParser dp = new DOMParser();
// Set Schema Object for Validation
dp.setXMLSchema(schemadoc);
dp.setValidationMode(XMLParser.SCHEMA_VALIDATION);
dp.setPreserveWhitespace (true);
StringWriter sw = new StringWriter();
dp.setErrorStream (new PrintWriter(sw));
try
dp.parse (in);
sw.write("The input XML parsed without errors.\n");
catch (XMLParseException pe)
sw.write("Parser Exception: " + pe.getMessage());
catch (Exception e)
sw.write("NonParserException: " + e.getMessage());
return sw.toString();
This is the code i used initially for validating a xml file against single xml schema (.xsd) file
In the above code could u tell how to specify the second schema validation code for the incoming xml.
say i create another Schemadoc for the 2nd xml schema.
something like this with another parameter(CHAR xsd1) passing to the method
byte [] docbytes1 = xsd1.getBytes();
ByteArrayInputStream in1 = new ByteArrayInputStream(docbytes1);
XMLSchema schemadoc1 = (XMLSchema)builder.build(in1,null);
DOMParser dp = new DOMParser();
How to set for the 2nd xml schema validation in the above code or can i combine 2 xml schemas.
How to go about it
Rgrds
Sushant -
Is schema validation on JDK 1.3.1 possible ?
Hi
I'm trying to get an XML parser to work on 1.3.1 with Schema validation.
API xerces.jar doesn't seem to handle schema validation in that version.
I tried my project with xercesImpl.jar on 1.4.2_09 => schema validation worked well.
I tried xerces.jar on 1.3.1 => doesn't run
Is there a .jar that can handle schema validation in 1.3.1 ?
Thanks
MontelieriHey.
In looking at their site, xerces 1.4.4 is the latest release, and is the one that provides support for XML Schema Version 1.0. This version likely requires JDK 1.4.x. You should double check the readme file in the dl.
http://xml.apache.org/xerces-j/index.html
Not a definate answer, but hope it helps anyway.
Cheers. -
Catch all error information while validating xml content with xsd schema
Hi experts,
I created a java mapping to validating the input xml content with xsd schema (schema validation). What I want is to catch all error message to the xml not just the first error. I used SAXParser in sapxmltoolkit.jar to do the schema validation. The below is a part of my java mapping.
XMLReader parser = XMLReaderFactory.createXMLReader("com.sap.engine.lib.xml.parser.SAXParser");
parser.setFeature( "http://xml.org/sax/features/validation" , true);
parser.setFeature( "http://apache.org/xml/features/validation/schema" , true);
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",this.getClass().getClassLoader().getResourceAsStream(schema)); // schema is my schema name
parser.setErrorHandler(new ParseErrorHandler()); // ParseErrorHandler is my own ErrorHandler which extends DefaultHandler
parser.parse(new InputSource(new ByteArrayInputStream(sinput.getBytes())));
// In error handler, I comment all code so as not to throw any exception
public class ParseErrorHandler extends DefaultHandler
public void error(SAXParseException e) throws SAXException
// sSystem.out.println("Error" + e.getMessage());
// throw e;
public void fatalError(SAXParseException e)
// throw e;
// System.out.println("SAP Fatal Error" + e.getMessage());
Unfortunately the program always stopped while catching the first error. Check the below log.
com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException:
ERRORS :
cvc-simple-type : information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is not valid, because it's value does not satisfy the constraints of facet 'minLength' with value '1'.
cvc-data : information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is is not valid with respoct to the corresponding simple type definition.
cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' is associated with invalid data.
cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]' is not valid with respect to it's complex type definition..
cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]' is not valid with respect to it's complex type definition..
cvc-element : element information item '/:ShipNotice[1]/:Header[1]/:To[1]' is not valid with respect to it's complex type definition..
cvc-element : element information item '/:ShipNotice[1]/:Header[1]' is not valid with respect to it's complex type definition..
cvc-element : element information item '/:ShipNotice[1]' is not valid with respect to it's complex type definition..
-> com.sap.engine.lib.xml.parser.ParserException:
I tried using Xerces and JAXP to do validation, the same error happened. I have no idea on this. Does xi has its own error handler logic? Is there any body can make me get out of this?
Thanks.<h6>Hi experts,
<h6>
<h6>I created a java mapping to validating the input xml content with xsd schema (schema validation). What I want is to catch all <h6>error message to the xml not just the first error. I used SAXParser in sapxmltoolkit.jar to do the schema validation. The below <h6>is a part of my java mapping.
<h6>XMLReader parser = XMLReaderFactory.createXMLReader("com.sap.engine.lib.xml.parser.SAXParser");
<h6>parser.setFeature( "http://xml.org/sax/features/validation" , true);
<h6>parser.setFeature( "http://apache.org/xml/features/validation/schema" , true);
<h6>parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); <h6>parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",this.getClass().getClassLoader().getResourceAsStream(schema)); <h6>// schema is my schema name
<h6>parser.setErrorHandler(new ParseErrorHandler()); // ParseErrorHandler is my own ErrorHandler which extends Default Handler
<h6>parser.parse(new InputSource(new ByteArrayInputStream(sinput.getBytes())));
<h6>
<h6>// In error handler, I comment all code so as not to throw any exception
<h6>public class ParseErrorHandler extends DefaultHandler
<h6>{
<h6> public void error(SAXParseException e) throws SAXException
<h6> {
<h6> // sSystem.out.println("Error" + e.getMessage());
<h6> // throw e;
<h6> }
<h6>
<h6> public void fatalError(SAXParseException e)
<h6> {
<h6> // throw e;
<h6> // System.out.println("SAP Fatal Error" + e.getMessage());
<h6>
<h6> }
<h6>
<h6>}
<h6>
<h6>Unfortunately the program always stopped while catching the first error. Check the below log.
<h6>
<h6>com.sap.engine.lib.xml.parser.NestedSAXParserException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException:
<h6>ERRORS :
<h6>cvc-simple-type : information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' <h6>is not valid, because it's value does not satisfy the constraints of facet 'minLength' with value '1'.
<h6>cvc-data : information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' <h6>is is not valid with respoct to the corresponding simple type definition.
<h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]/:CityName[1]' <h6>is associated with invalid data.
<h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]/:AddressInformation[1]' <h6>is not valid with respect to it's complex type definition..
<h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]/:PartnerInformation[1]' <h6>is not valid with respect to it's complex type definition..
<h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]/:To[1]' <h6>is not valid with respect to it's complex type definition..
<h6>cvc-element : element information item <h6>'/:ShipNotice[1]/:Header[1]' <h6>is not valid with respect to it's complex type definition..
<h6>cvc-element : element information item '/:ShipNotice[1]' is not valid with <h6>respect to it's complex type definition..
<h6> -> com.sap.engine.lib.xml.parser.ParserException:
<h6>
<h6>
<h6>I tried using Xerces and JAXP to do validation, the same error happened. I have no idea on this. Does xi has its own error <h6>handler logic? Is there any body can make me get out of this?
<h6>Thanks. -
This is an example of schema validating with error feedback
Hi,
Hope this is of help....
This is an example of schema validating WITH error feedback
public boolean validate(InputStream is) {
// create and setup the DOM parser object
parser = new DOMParser();
parser.setPreserveWhitespace(false);
parser.setValidationMode(XMLConstants.SCHEMA_STRICT_VALIDATION);
boolean isValid = false;
if (is != null) {
try {
parser.parse(new InputSource(is));
isValid = true;
} catch (XMLParseException e) {
for (int i = 0; i<e.getNumMessages() ;i++){
System.out.println("XMLParseException nr:"+new Integer(i+1)+" \'imsmanifest.xml\' line nr: "+new Integer(e.getLineNumber(i))+" col nr:"+
new Integer(e.getColumnNumber(i))+" (formatErrorMessage: "+e.formatErrorMessage(i)+") ["+e.getMessage(i)+"]");
} catch (java.io.IOException e) {
System.out.println("IOException: Error creating input source [" + e.getMessage() + "]");
} catch (org.xml.sax.SAXException e) {
System.out.println("SAXException: Error parsing [" + e.getMessage() + "]");
} catch (Exception e){
System.out.println("Exception: Error parsing [" + e.getMessage() + "]. ");
doc = parser.getDocument();
return isValid;
regards
Jon"personally, I'd just put the exception handling into the package."
Maybe I am making this over-complicated. I would like all the error handling in the package. It seems like putting an ONSERVERERROR trigger would be a little overkill, and if it fires on every database error, and I have to screen for only my errors seems like a little overkill and to me, it seems like it would incur quite a bit of overhead for the database seeing it is firing for every error. I don't even know if I would ultimately be allowed to keep it.
Really, all I would want to do is:
1) Handle the error and recover if possible
2) If it is a fatal error, have a way to abort the package gracefully with some kind of record of it.
3) Allow for the possibility of non-fatal errors or messages, even that I might generate myself to be able to be logged.
This package has about 20 procedures now. If I have an error (particularly fatal), in let's say, procedure 8, I don't even know what happens. I don't know if by default it aborts the whole package or just that procedure or just keeps going. Is it possible to get just hung up and sit there?
Thanks for the input.
Maybe you are looking for
-
Even though Firefox has been updated multiple times (currently using Ver. 3.6.13) since I started using Windows 7, I am still unable to totally close it from the toolbar or taskbar. Firefox does closeout on the screen but apparently continues to run
-
Missing Templates in iphoto how to get them back?
I'm using Macbook Pro with OS X 10.7.2 , i have iphoto version 9.2.1 (628) , Now when i use email in iphoto and i want to use the templates so they are missing can someone help me how to get them back?
-
Trouble connecting C4795 printer wirelessly
Ok, so here it what I have: Photosmart C4795 printer Mac Mini w/ OS X 10.9.5 Cisco DPC3825 router I have tried everything under the sun to connect this printer wirelessly to my computer to no avail. I have searched the internet high and low for a so
-
Error 403 when accessing iCalendar
When accessing iCalendar I receive the message error 403 on CalDAVAccountRefreshQueueableOperation. Can anyone tell me how to fix it?
-
Daylight Savings started in my country... Alarm clock time did not change
Hi, DST began in mexico. My iphone clock is set to "Mexico City" time zone and the clock indeed adjusted automatically to DST this past sunday. The iphone alarm (not a 3rd party app, but the original iphone alarm app) is what had a weird behavior...