Validate XML against Xml Schema using JDBC (thin_driver)
hi all,
i have a table with a xmltype-column (XmlSchema Support) and i wonna load(and validate) xml-data( as String) in the xmltype-column.
some thing like this :
int count=1;
String SQLTEXT=null;
Statement stmt=null;
ResultSet rs =null;
//while(count<=1000)
try
stmt = connection.createStatement();
rs = stmt.executeQuery("select SEQ_patxmlschema_ID.NEXTVAL from patxmlschema");
if(rs.next())
id =rs.getLong(1);
System.out.println(id);
stmt.close();
stmt=null;
rs.close();
SQLTEXT = "INSERT INTO patxmlschema(id, patID, name, status, patInfo)"+
"VALUES(?,?,?,?,XMLType(?))";
pStmt = connection.prepareStatement(SQLTEXT);
long patID = random.nextInt(30000);
System.out.println("patId: "+ patID);
String name = RandomStringUtils.random(6,true,false);
System.out.println("lastname: "+ name);
String firstname=RandomStringUtils.random(5,true,false);
System.out.println("firstname: "+ firstname);
String status=RandomStringUtils.random(8,true,false);
System.out.println("status: "+ status);
String street=RandomStringUtils.random(6,true,false);
System.out.println("street: "+ street);
String zip=RandomStringUtils.random(5,false,true);
System.out.println("zip: "+ zip);
String city=RandomStringUtils.random(6,true,false);
System.out.println("city: "+ city);
String phone=RandomStringUtils.random(8,false,true);
String email=RandomStringUtils.random(15,true,false);
String state=RandomStringUtils.random(6,true,false);
String country=RandomStringUtils.random(6,true,false);
System.out.println("country: "+ country);
xmldoc=
"<Patient>"+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+ "xsi:noNamespaceSchemaLocation='http://olidong.net/patInfo.xsd'>"+
"<Address>"+ "<street>"+street+"</street>"+ "<city>"+city+"</city>"+ "<zip>"+zip+"</zip>"+
"<state>"+state+"</state>"+ "<country>"+country+"</country>"+
"</Address>"+ "<phone>"+phone+"</phone>"+ "<email>"+email+"</email>"+
"</Patient>";
pStmt.setLong(1, id);
pStmt.setLong(2, patID);
pStmt.setString(3, name);
pStmt.setString(4, status);
pStmt.setString(5, xmldoc);
pStmt.executeUpdate();
pStmt.close();
pStmt=null;
count++;
//connection=null;
catch(Exception e){
e.printStackTrace();
can you help me?
Olidong
hi Avi,
my xml doc is valid. with the sqlplus the are no problem or error. tryng the same with jddbc(thin driver) i got this error.
i don´t know, may be jdbc don´t support xml schema support insertion.
i got this sample:
DECLARE
doc VARCHAR2(2000) :=
'<schema
targetNamespace="http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd"
xmlns:po="http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<complexType name="PurchaseOrderType">
<sequence>
<element name="PONum" type="decimal"/>
<element name="Company">
<simpleType>
<restriction base="string">
<maxLength value="100"/>
</restriction>
</simpleType>
</element>
<element name="Item" maxOccurs="1000">
<complexType>
<sequence>
<element name="Part">
<simpleType>
<restriction base="string">
<maxLength value="20"/>
</restriction>
</simpleType>
</element>
<element name="Price" type="float"/>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
<element name="PurchaseOrder" type="po:PurchaseOrderType"/>
</schema>';
BEGIN
DBMS_XMLSCHEMA.registerSchema(
'http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd', doc);
END;
CREATE TABLE mypurchaseorders OF XMLType
XMLSchema "http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd"
ELEMENT "PurchaseOrder"
VARRAY xmldata."Item" STORE AS TABLE item_nested;
INSERT INTO mypurchaseorders
VALUES(
XMLType(
'<PurchaseOrder
xmlns="http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
= "http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd
http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd">
<PONum>1001</PONum>
<Company>IBM</Company>
<Item>
<Part>DB2 v9 Set</Part>
<Price>2550</Price>
</Item>
<Item>
<Part>8i Doc Set</Part>
<Price>350</Price>
</Item>
</PurchaseOrder>'));
with the sqlplus the are no error
but insert with java jdbc:
SQLTEXT = "INSERT INTO mypurchaseorders VALUES(XMLType(?))";
String xmldoc= "<PurchaseOrder"+
"xmlns='http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd'" +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
"xsi:schemaLocation= 'http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd'"+
"'http://xmlns.oracle.com/xdb/documentation/purchaseOrder.xsd'>"+
"<PONum>1001</PONum>"+
"<Company>IBM</Company>"+
"<Item> "+
"<Part>DB2 v9 Set</Part>"+
"<Price>2550</Price>"+
"</Item>"+
"<Item>"+
"<Part>8i Doc Set</Part>"+
"<Price>350</Price>"+
"</Item>"+
"</PurchaseOrder>";
pStmt.setString(1, xmldoc);
i got this error
java.sql.SQLException: ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00240: element-start tag is not well formed
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 301
ORA-06512: at line 1
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:952)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1160)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368)
at xml_tab.doInsert(xml_tab.java:118)
at xml_tab.main(xml_tab.java:138)
could you help me?
Olidong
Similar Messages
-
Error while Validating xml against a schema using jaxp
Hi All,
Following code validates xml against a schema using JAXP .It gives SAXNotRecognizedException error when you run the program.
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";
SAXParserFactory myFactory = SAXParserFactory.newInstance();
myFactory.setNamespaceAware(true);
myFactory.setValidating(true);
javax.xml.parsers.SAXParser parser;
String filename = "C:/Note.xml";
File xmlFile = new File(filename);
try
DefaultHandler handler = new DefaultHandler();
parser = myFactory.newSAXParser();
parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
parser.parse(xmlFile, handler);
catch (ParserConfigurationException e)
// TODO Auto-generated catch block
e.printStackTrace();
catch (SAXException e)
// TODO Auto-generated catch block
e.printStackTrace();
catch (IOException e)
// TODO Auto-generated catch block
e.printStackTrace();
Error Details :
org.xml.sax.SAXNotRecognizedException: http://java.sun.com/xml/jaxp/properties/schemaLanguage
at org.apache.xerces.framework.XMLParser.setProperty(XMLParser.java:1682)
at org.apache.xerces.parsers.SAXParser.setProperty(SAXParser.java:770)
at org.apache.xerces.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:183)
How do i fix the above mentioned problem ?
Thanks in Advance.
AnshValidate with the JAXP DOMParser instead of the JAXP SAXParser.
To validate with a SAXParser use the xerces SAXParser.
thanks,
Deepak -
Does XDB supports validating xml against multiple schemas?
The XMLType has some methods for validating an xml documents against a schema, e.g., SCHEMAVALIDATE, etc.. does XDB support validating xml against multiple schemas (Just like what JAXP or Xerces have done)? Or what's the current situation about this issue? thanks.
did you try using the import schema element instead of the include elemnt?
-
Validate XML against XML Shema while marshalling/Unmarshalling in JAXB?.
Hi,
Can i validate XML documents against XML Shema when i marshall/unmarshall the same using JAXB API?.
ThanksWell, it is weird, but, the code below works when validating the NonEmptyString type:
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(null, "LogConfig.xsd");
XDocument doc1 = XDocument.Load("LogConfig.xml");
doc1.Validate(schemaSet, new ValidationEventHandler(ValidationCallBack), false);
However, if I leave the <LogName> empty it does not valid the values set on xsd fixed attribute,
The solution?
Well, I'm validating the same xml twice, the code above and the code on my first question. -
JDOMException thrown validating XML against a schema with Xerces2
I'm trying to validate a document with JDOM and Xerces 2.
I can validate it with XMLSpy (it works, my document is valid).
But with JDOM and xerces, this error occurs when parsing and validating my document:
org.jdom.JDOMException: Error on line 6 of document file:///E:/developpement/SitePerso/xml/xml/listeEntreprises.xml: cvc-complex-type.2.4.a: Invalid content starting with element 'item'. The content must match '(("":nom){0-1},("":item){0-UNBOUNDED})'.
My XML document:
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.3 U (http://www.xmlspy.com) by de Boussineau (none) -->
<!--Sample XML file generated by XML Spy v4.3 U (http://www.xmlspy.com)-->
<liste xmlns="E:/developpement/SitePerso/xml/domain~1/schemaListe" ... E:\developpement\SitePerso\xml\schemas\schemaListe.xsd">
<item xsi:type="xsel:typeEntreprise">
<xsel:nom>PHOENIX I.S.I.</xsel:nom>
<xsel:groupe>Taffioles</xsel:groupe>
<xsel:adresse>2 rue du centre</xsel:adresse>
The element <nom> before <item> is not required. So what's the problem ?...
-
Xml data from database using jdbc
I should get the xml data from database. Is this scenario possible using jdbc adapter ? If possible, how can I get it ?. Plz help me
I suppose that probably, xml data are stored in a BlobImage Field.
You can use a Stored Procedure on Database Side, to select and put out the xml data structured in output fields or structures.
From JDBC Sender channel, you can call the SP, that raise out a Structure formatted like the XML Data stored in Xml Database field.
In your opinion, this should be a possible way to achieve this issue? -
Issue in Store XML into Schema generated tables and Validation XML against registered schema.
Hello friends,
I am facing some problem when store xml into generated tables from registered schema.
This is my Schema
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.abc.inf.in/test" targetNamespace="http://www.abc.inf.in/test" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="abc.xsd"/>
<xs:element name="project" type="student">
<xs:annotation>
<xs:documentation> This is a Documentation</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
-- This is my xml document
<project versao="2.00" xmlns="http://www.abc.inf.in/test">
<test xmlns="http://www.abc.inf.in/test">
<intest version="2.00" Id="testabc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<ide>
<cUF>35</cUF>
<cNF>59386422</cNF>
<natOp>this is post</natOp>
<indPag>1</indPag>
<mod>55</mod>
<serie>1</serie>
</ide>............
Not giving full because it's too long.
1. I Successfully registered Schema into database
2. Then i generate table from registered Schema
2. In my java code i validated XML document against Schema and it's successfully validate.
3. But when i stored this XML into this generated table it's give me error
Like :
INSERT INTO XMLTABLE
VALUES
(XMLTYPE(bfilename('MYDIR','testabc.xml'),NLS_CHARSET_ID('AL32UTF8')))
Error report:
SQL Error: ORA-31061: XDB error: XML event error
ORA-19202: Error occurred in XML processing
LSX-00333: literal "94032000" is not valid with respect to the pattern
And i have to store this xml into this tables so what i have to do ?Thanks for your reply odie_63.
I got this my error solution. My XML document is not well structured based on my registered XML Schema.
Means In My XML Document there are some invalid value and that not match my schema pattern so it's gives this error
SQL Error: ORA-31061: XDB error: XML event error
ORA-19202: Error occurred in XML processing
LSX-00333: literal "94032000" is not valid with respect to the pattern
For Solution we have two ways
1. I have changed this literal "94032000" value in my xml file then save it.
2.
- We have to delete this schema then
- we have to change Schema pattern for particular element
like :--
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:pattern value="[0-9]{3}"/>
</xs:restriction>
- then store xml into database it works..
Thanks. -
How to validate XML against Schema
Hi,
I am trying to validate the XML against the schema by using follywing code but i am never getting errors in parser it always passes the parser even though there are serious parsing problems. My code is as follows:
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser sp = spf.newSAXParser();
sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdPath);
DefaultHandler dh = new DefaultHandler();
sp.parse(splObjPath, dh);
thanksMany ways to do this... also depending upon what version of Xerces and/or you want to do DTD or schema, etc one of the simplest is to set the following properties,
refer to:
http://xerces.apache.org/xerces2-j/features.html
Scroll down, check all the features starting with "http://apache.org/xml/features/validation" -
Can not validate XML against schema
Hi all,
I'm new to XML validation. I have this sample from net.
this is the schema definition:
<xs:schema targetNamespace="http://www.w3schools.com" elementFormDefault="qualified">
<xs:element name="note" type="xs:string"/>
</xs:schema>
and this is the xml file:
<?xml version="1.0"?>
<note xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
when i try to validate at http://schneegans.de/sv/, this is a validator i found searching
it gives error
The root element does not comply with the schema. (2:2)
any ideas?
i have created my own xml and schema.I registered the xsd on oracle 10g but i get the same error :(
where can i validate my xml against a schema?
thanx a lotValidating XML Documents Against XML Schema
http://www.oracle.com/technology/pub/articles/vohra_xmlschema.html -
Validate xml againt registerd schema, ignoring xsi:noNamespaceSchemaLocatio
hi,
i would like to validate received xml against registered schema, ignoring the one defined in xml. I use XMLisValid(xml_data ,schema_url) but it works only if there is no xsi:noNamespaceSchemaLocation attrubute.
This is sample xml.
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSPY v2004 rel. 3 U (http://www.xmlspy.com)-->
<ROOT xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://localhost/public/xsd/myapp.xsd">
<ID>0</ID>
<INFO>
<INFO_ID>0</INFO_ID>
<INFO_CONTENT>Text</INFO_CONTENT>
</INFO>
</ROOT>
Anybody knows if it is possible?
Thanks in advance..Hi,
It should work according to the documentation, but obviously it doesn't.
So I guess you'll have to consider one of these options :
- Changing the xsi:noNamespaceSchemaLocation at the source to use the URL of your registered schema instead
- The other way around : register your schema at the URL defined in the document
- Removing the xsi:noNamespaceSchemaLocation attribute prior to validation
Here's an example for the third option :
BEGIN
dbms_xmlschema.registerSchema(
schemaURL => 'myapp2.xsd'
, schemaDoc =>
'<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ROOT">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:integer"/>
<xs:element name="INFO">
<xs:complexType>
<xs:sequence>
<xs:element name="INFO_ID" type="xs:integer"/>
<xs:element name="INFO_CONTENT" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>'
, local => true
, genTypes => false
, genTables => false
END;
SQL> declare
2
3 doc xmltype := xmltype('<?xml version="1.0" encoding="UTF-8"?>
4 <ROOT xmlns:xdb="http://xmlns.oracle.com/xdb"
5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6 xsi:noNamespaceSchemaLocation="http://localhost/public/xsd/myapp.xsd">
7 <ID>0</ID>
8 <INFO>
9 <INFO_ID>0</INFO_ID>
10 <INFO_CONTENT>Text</INFO_CONTENT>
11 </INFO>
12 </ROOT>');
13
14 isValid integer;
15
16 begin
17
18 doc := doc.deleteXML('/ROOT/@xsi:noNamespaceSchemaLocation','xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"');
19
20 select xmlisvalid(doc, 'myapp2.xsd') into isValid from dual;
21
22 dbms_output.put_line('isValid = '||to_char(isValid));
23
24 end;
25 /
isValid = 1
PL/SQL procedure successfully completed -
How to parse XML against Schema (XSD)
Hi,
I am trying to parse the XML against the schema by using follywing code but i am never getting errors in parser it always passes the parser even though there are serious parsing problems. My code is as follows:
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser sp = spf.newSAXParser();
sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdPath);
DefaultHandler dh = new DefaultHandler();
sp.parse(splObjPath, dh);Hi,
I am trying to parse the XML against the schema by using follywing code but i am never getting errors in parser it always passes the parser even though there are serious parsing problems. My code is as follows:
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser sp = spf.newSAXParser();
sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", xsdPath);
DefaultHandler dh = new DefaultHandler();
sp.parse(splObjPath, dh); -
Question about validating xml against schema
Hi,
I am new to JAXP. I try to validating a xml against a schema. I wrote following code:
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespace(true);
spf.setValidating(true);
SAXParser sp = spf.newSAXParser();
sp.setProperty("http://java.sun.com/xml/properties/jaxp/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
sp.setProperty("http://java.sun.com/xml/properties/jaxp/schemaSource",
"mySchema.xsd") ;
sp.parse(<XML Document>, <ContentHandler);
but when compile, it has error: can't resolve ""http://java.sun.com/xml/properties/jaxp/schemaLanguage", and
"http://java.sun.com/xml/properties/jaxp/schemaSource".
It seems it didn't support above two property.
I saw some code in forum is:
fact.setFeature("http://xml.org/sax/features/validation", true);
fact.setFeature("http://apache.org/xml/features/validation/schema",true);
fact.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
SAXParser sp = fact.newSAXParser();
sp.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schemas);
Why sun tutorial use property:http://java.sun.com/xml/properties/jaxp/schemaLanguage
and someone use:http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
where to get information about setting properties for SAXParserFactory?
ThanksIn the past, ColdFusion's XML validation mechanism seems to have had issues with schemas that contain imports, e.g., http://forums.adobe.com/message/155906. Have these issues still not been resolved?
Do you not think that perhaps you're answering your own question here?
I don't see an issue about this on the bug tracker. It might be an idea if you can get a simple, stand-alone repro case together and raise an issue (and post the reference back here and against that other thread so people know to vote for it). If you post the repro case here too, it would be helpful.
Adam -
Validating a xml aggainst a schema
Hi Everyone,
Can you please let me know of any easy procedure to validate an xml against a schema in BPEL?
I tried many things but am still stuck up.
Thanks,
MannuHi Mannu,
Define a second bpel-process ( asynchronous ) base its input message on the schema you want to validate against.
In the latest release this is very easy.
Delete the reply activity (optional).
deploy this ( to a separate domain)
In your main process add this process as a partnerlink
Add the validateXML property to the partnerlink and set it to "true"
Invoke it with the xml you want validated .
When you do this in a scope you can catch
the bpelx:invalidVariables exception
and inspect a fault variable ( based on the RuntimeFaultMessage found in RuntimeFault.wsdl) for the violation etc.
Et voila.
HTH
Mark -
JAXB: How to unmarshal from xml contains two schemas?
Hi, all.
My question is in subject.
Ex.)
schema1.xsd:
(snip)...
<xsd:element name="xxx">
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
...(snip)
schema2.xsd:
(snip)...
<xsd:element name="yyy">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="zzz" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="zzz" type="xsd:string"/>
if I have a xml like the following, xml validation is correct:
sample.xml:
(snip)...
<ns1:xxx xmlns:ns1="...(schema1.xsd)...">
<ns2:yyy xmlns:ns2="...(schema2.xsd)...">
<ns2:zzz>SAMPLE</ns2:zzz>
</ns2:yyy>
</ns1:xxx>
I want to unmarshal from this xml using JAXB, but actually ths xxx didn't have any tag in List class given getAny() method, because xxx doesn't know about yyy, I think.
These schemas cannot change as requirements of customer.
How to unmarshal from xml contains two schemas using JAXB?
tx.I solved it myself.
JAXBContext can be specified many context path at same time.
Ex.)
context = JAXBContext.newInstance("package1:package2:package3...");
So, unmarshaller can know how to choose what be instanced.
tx. -
Validating XML against an XML Schema using PL/SQL
Hello everyone,
I've a strange problem.
I'm trying to validate an XMLTYPE variable against an XSD schema using the XMLisValid function.
The XML I was trying to validate was returning false (0) when using this method.
However, when I register the XSD against a column in a table and then insert this XMLTYPE into that column, I do not get any errors. If I change the XSD to ensure failure when using this method, I do get an error, so it is registered and working.
I have then created a very basic XSD and both methods work when validating the XML against this. So obviously the more complicated XSD I want to validate against is making a difference, but I would expect them to either both fail or both pass, not one fail and one pass.
Does anyone know why they'd be returning different results?
Thanks in advance for your help.
Robin
examples of what I'm using:
XML to validate:
<centres>
<add>
<centre>
<centreName>Name 1</centreName>
<centreRef>45678</centreRef>
</centre>
</add>
</centres>
Simple XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="centres" type="centresType"/>
<xs:complexType name="addType">
<xs:sequence>
<xs:element type="xs:string" name="centreName"/>
<xs:element type="xs:short" name="centreRef"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="centresType">
<xs:sequence>
<xs:element type="addType" name="add" maxOccurs="3" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Complicated XSD:
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML Studio - 30 Day Trial Edition 7.1.6.1440 (http://www.liquid-technologies.com)-->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="centres">
<xs:complexType>
<xs:sequence>
<xs:element name="remove">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1000" name="centreRef">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="add">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1000" name="centre">
<xs:complexType>
<xs:sequence>
<xs:element name="centreName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="100" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="centreRef">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="qualifications">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1000" name="qualRef">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="100" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="modifyQualAssociations">
<xs:complexType>
<xs:sequence>
<xs:element name="remove">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1000" name="r">
<xs:complexType>
<xs:attribute name="centreRef" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="qualRef" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="100" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="add">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1000" name="a">
<xs:complexType>
<xs:attribute name="centreRef" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="qualRef" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="100" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>Steps to validate XML data against a schema in Oracle:
1. Register your XSD in the database.
begin
dbms_xmlschema.registerschema(
SchemaUrl,
SchemaDoc,
local => TRUE/FALSE);
end;
2. For validating your XML document against your registered schema, here is a sample pl/sql block.
declare
v_xml xmltype;
begin
v_xml := your_xml_document;
v_xml.schemaValidate();
end;
Hope this helps :)
Maybe you are looking for
-
Neo2 Memory ratio issues, please read
hey all very strang stuff... just got a 3200+ winchester .90 CPU, its nice. also have 2x twinx corsair 3200 non LL ram. idea: I had in mind that since my ram doesnt OC very well (220 max) I was going to get the neo2 and play with the FSB and set the
-
3D environment in pure java programming
hi all, my problem is dat... import java.awt.*; import java.applet.*; import java.awt.event.*; </applet code="project1" width=1024 height=768> </applet> public class project1 extends Frame implements ActionListener , MouseListener { deathscreen
-
Will the MacBook Pro need a SIM card or any type of plan
I'd like to know if there was a need to put a SIM card or some sort of insert when I get the MacBook . Do I need a plan to operate the laptop ? Aswell as programming ... Will Microsoft word and PowerPoint be included with the system or will I need to
-
How do i remove blurs in the pic
the pic that i am editing is blury and i am tying to see what tool i can use. is there a "lens flare" tool that can do this
-
When composing an email, how can I highlight a web address and convert it into a link such that someone can simply click on it to go to the designated address?