Validating XML with external dtd without doctype specified in xml
Hi,
I am very new to SAX, DOM and things..but I am really pulling my hair to find the soln., I have tried to search soln but I found many people asking same question but hardly anyone was satisfactory.
My problem is that I have xml file without doctype specified in it, but I have dtd available on my system.
I have tried to set MyEntityResolver which implements EntityResolver in documentBuilder but its only getting called (resolveEntity method of MyEntirtyResolver), only when I add doctype to the xml (which is not what I want) and not when there is no doctype in the xml. I have set "factory.setValidating(true)" and I also have errorHandler in place.
But why EntityResolver is not invoked when its needed most. ie. when doctype is not available in xml ?...it complains that DOCTYPE must match root=null , which is obvious because no DOCTYPE in xml.
code is as follows:
please help me ..if anyone has any idea about this ....
Main class is :
public static void main(String args[]){
Document document=null;
ErrorHandler defaultHandler=new MyDefaultHandler();
String xmlFile="note.xml";
try{
System.out.println("Starting...");
boolean validXML = true;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
try {
ExternalResolver er = new ExternalResolver();
// addURL is just a method which sets string in a map to be retrieved by resolveEntiy
er.addURL("D:\\SAXnDOM\\SAXProject\\note.dtd");
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(er);
builder.setErrorHandler(new MyDefaultHandler());
builder.parse(new File(xmlFile));
resolveEntity of ExternalResolver is as follows:
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
System.out.println("********resolvedEntity:" +publicId +" and "+systemId +"******");
if ( urlMap != null && urlMap.get(systemId)!= null ){
try {
return new InputSource(new FileReader(systemId));
} catch (FileNotFoundException e) {
System.out.println("[ERROR] Unable to load entity reference: " + systemId );
return null;
public void addURL(String filePath) throws MalformedURLException{
addURL(new File(filePath).toURL());
public void addURL(URL url) {
if ( urlMap == null ){
urlMap = new HashMap();
urlMap.put(url, null);
}
Its working.... its working ...
problem was in resolveEntity, that stupid if condition was removed like this:
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
System.out.println("********resolvedEntity:" +publicId +" and "+systemId +"******");
try {
return new InputSource("D:\\SAXnDOM\\SAXProject\\note.dtd");
} catch (Exception e) {
System.out.println("[ERROR] Unable to load entity reference: " + systemId );
return null;
}Other change is (which I didnt like ) is that in my xml, I had written fake doctype like :
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "fakenote.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<Prashant>prdfjfdj</Prashant>
</note> in above code fakenote.dtd doesnt exist anywhere ..its just to bypass that doctype:null error.
So my guess is that EntityResolver overrides doctype in the xml and applies its own doctype (note.dtd in this case)
But new proble comes...what if i dont want to add any doctype ..not even fake in xml ?
Hope my stupid mistakes will find someone usefull..
Similar Messages
-
ORA-31020 when using XML with external DTD or entities
I'd like to parse XML documents against a modular DTD that references other DTDs. This works fine with Oracle 9i. But after upgrading to 11g, the parsing of XML-instances fails and DBMS_XMLPARSER.parseClob produces ORA-31020.
The same error occurs even if I simply try to store XML with a reference to an external DTD as xmltype:
SQL> select xmltype('<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE ewl-artikel SYSTEM "http://www.foo.com/example.dtd"><test>123</test>') from dual;
ERROR:
ORA-31020: Der Vorgang ist nicht zulässig, Ursache: For security reasons, ftp
and http access over XDB repository is not allowed on server side
ORA-06512: in "SYS.XMLTYPE", Zeile 310
ORA-06512: in Zeile 1
How can I use external DTDs on remote servers in order to parse XML in an 11g database??? Any ideas for a workaround? Thanks in advance!This is my PL/SQL validation procedure:
procedure validatexml (v_id in number default 0) is
PARSER DBMS_XMLPARSER.parser;
DTD_SOURCE clob;
DTD_DOCUMENT xmldom.DOMDocumentType;
XML_INSTANCE xmltype;
BEGIN
-- load DTD from XDB repository
SELECT httpuritype('http://example.foo.de/app1/DTD1.dtd').getclob() into DTD_SOURCE from dual;
-- load XML instance
select co_xml into XML_INSTANCE from tb_xmltab where co_id=v_id;
-- parse XML instance
PARSER := DBMS_XMLPARSER.newParser;
xmlparser.setValidationMode( PARSER , false);
xmlparser.parseDTDClob( PARSER , DTD_SOURCE , 'myfirstnode' );
DTD_DOCUMENT := xmlparser.getDoctype( PARSER );
xmlparser.setValidationMode( PARSER , true );
xmlparser.setDoctype( PARSER , DTD_DOCUMENT );
DBMS_XMLPARSER.parseClob( PARSER , v_xml );
DBMS_XMLPARSER.freeParser(PARSER);
htp.print('<P>XML instance succesfully validated!<P>');
end validatexml; -
XML VALIDATION WITH EXTERNAL DTD
I've the following problem:
I've stored a dtd into the xdb repository(with createresource function) and all seems work.
In this DTD i've declared some element and one entity in this way :
<!ENTITY emsp " " ><!--=em space-->
When i try to store or extract my xml (with sql extract function) i get :
ORA-19202 Error during xml processing
LPX-00217 : invalid character 8195 (\u2003)
I've to declare the entity in a different way ?
Thanks in advance
GiovanniYou might want to check out the XML DB forum FAQ rather than ask XML questions on the SQL and PL/SQL forum:
XML DB FAQ -
Hello!
How can the Oracle XML-Parser parse a XML-Document without the
XML-Declaration. There is no information about the Version and
the DTD in the XML-Document. Can I use an extern DTD?
Thanks,
Peter
nullPeter Roemer (guest) wrote:
: Hello!
: How can the Oracle XML-Parser parse a XML-Document without the
: XML-Declaration. There is no information about the Version and
: the DTD in the XML-Document. Can I use an extern DTD?
: Thanks,
: Peter
Have you tried oracle.xml.parser.v2.XMLParser.setDoctype(DTD)?
Oracle XML Team
http://technet.oracle.com
Oracle Technology Network
null -
Validating XML with its DTD in JSP
Is there a way to validate an XML file with its DTD, using a JSP ???
If YES, then HOW???
I hope my question is clear enough.
Please help!!Thanks "Jleech",
I am using a textarea in a JSP to input for an XML file. The JSP transfers the file to Web-Server, which also has XERCES installed. My question is how can u Validate this transfered XML file with its DTD. My problem is I don't to how to include that Validation program in JSP.?
Could you still help??? -
Validating xml with external schema
Hi,
I want to validate a xml against an external schema using java and the xml WILL NOT contain any reference to the schema. Any help in the matter is most welcome.
A typical example of such an xml is given below:
<Envelope >
<Body>
" Some content here"
</Body>
</Envelope>
I used the following code but it did not validate the xml.It simply parsed.
public class TestParser {
public static void main(String[] args) {
final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
try {
SAXParserFactory saxpfactory = SAXParserFactory.newInstance();
saxpfactory.setNamespaceAware(true);//
saxpfactory.setValidating(true);//
SAXParser parser = saxpfactory.newSAXParser();
parser.setProperty(JAXP_SCHEMA_LANGUAGE, "http://www.w3.org/2001/XMLSchema");//
parser.setProperty(JAXP_SCHEMA_SOURCE, "http://www.w3.org/2001/06/soap-envelope");//
parser.parse(new File("C:\\TEMP\\request.xml"), new DefaultHandler());
} catch (FileNotFoundException fileNotFoundException) {
fileNotFoundException.printStackTrace();
} catch (IOException ioException) {
ioException.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("exiting main ");
RegardsIn the schema root element xs:schema add namespace declaration.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
In the XML document root element add xmlns:xsi and xsi:noNamespaceSchemaLocation attributes.
<root_element xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file://c:/testing.xsd"> -
Hi all!
I create XML and DTD. All working fine when I open it in MS XMLNotepad.
But when I try to load my XML in validating mode I get error
Error opening external DTD 'ReportsDTD.dtd'.
I open my XML through class loader as resource stream and then load it from this stream.
In XML I have such string
<!DOCTYPE DEFINITIONS SYSTEM "ReportsDTD.dtd">
Both xml and dtd are located in same directory.
Can anybody explain me whats wrong?
MikeReading from a stream, the parser has no idea what the "current directory" is.
So, when you reference a relative URL like "ReportsDTD.dtd", this means to find the DTD in the "same directory" as the current XML document.
You need to properly set the Base URL of the original input stream so that the parser knows what the base directory is.
Or, alternatively you can use getResource on the Class object that returns a URL and that has embedded within it the correct base URL "directory" info to work correctly.
So, if I have a "foo.xml" file that references "foo.dtd" inside, I can use the following code:
import java.net.URL;
import oracle.xml.parser.v2.*;
public class Class1
public static void main(String[] a) throws Throwable {
Class1 c = new Class1();
URL u = c.getClass().getResource("foo.xml");
DOMParser p = new DOMParser();
p.parse(u);
p.getDocument().print(System.out);
public Class1() { }
}Steve Muench
Development Lead, Oracle XSQL Pages Framework
Lead Product Manager for BC4J and Lead XML Evangelist, Oracle Corp
Author, Building Oracle XML Applications
null -
Validating XML stored in CLOB without exceptions for malformed XML
Hello,
I have a CLOB column that should contain an XML which conforms to a registered XSD schema. However, there might also be cases, in which the CLOB content violates the XSD or is not even wellformed XML at all. Now I am trying to find a way to either
identify all records, for which the CLOB contains well-formed XML that validates against my schema (find all "good" records) , or
find all the other records (those with either no XML at all, malformed XML, or XML that does not validate against the XSD) (find all "exceptions")
The problem is that all XML-validation methods I know of (e.g. isXmlValid or XmlType.isSchemaValid) require an XmlType instance, and that records, for which no proper XmlType can be constructed from the CLOB, because the CLOB does not contain well-formed XML, will cause an exception, rather than just returning false or NULL or something else I could filter out.
Is there a way to do something like
SELECT * FROM MYTABLE where <MY_XML_COL is wellformed XML> and <MY_XML_COL validates against 'blabla.xsd'>
without getting an ORA-31011 or whatever other kind of exception as soon as there is a row that does not contain proper XML?
Thank you...So here is my example - this will be quiet a long post now...
First, I create the table with the CLOBs
CREATE TABLE ZZZ_MINITEST_CLOB (
ID NUMBER(10,0) NOT NULL ENABLE,
XML_DOC CLOB,
REMARKS VARCHAR2(1000),
CONSTRAINT PK_ZZZ_MINITEST_CLOB PRIMARY KEY (ID)
) NOLOGGING;
Then I insert some examples
INSERT INTO ZZZ_MINITEST_CLOB VALUES (
10,
'<minitest_root>
<l2Node>
<l2Num>1</l2Num>
<l2Name>one.one</l2Name>
</l2Node>
<minitestId>1</minitestId>
<minitestName>One</minitestName>
</minitest_root>',
'Basic valid example');
INSERT INTO ZZZ_MINITEST_CLOB VALUES (
20,
'<minitest_root>
<l2Node>
<l2Num>1</l2Num>
<l2Name>two.one</l2Name>
</l2Node>
<minitestId>2</minitestId>
<!-- minitestName element is missing -->
</minitest_root>',
'Invalid - minitestName element is missing');
INSERT INTO ZZZ_MINITEST_CLOB VALUES (
30,
'<minitest_root>
<l2Node>
<l2Num>1</l2Num>
<l2Name>three.one</l2Name>
</l2Node>
<!-- minitestName and minitestId are switched -->
<minitestName>Three</minitestName>
<minitestId>3</minitestId>
</minitest_root>',
'Invalid - minitestName and minitestId are switched');
INSERT INTO ZZZ_MINITEST_CLOB VALUES (
40,
'<minitest_root>
<l2Node>
<l2Num>1</l2Num>
<l2Name>four.one</l2Name>
</l2Node>
<l2Node>
<l2Num>2</l2Num>
<l2Name>four.two</l2Name>
</l2Node>
<l2Node>
<l2Num>3</l2Num>
<l2Name>four.three</l2Name>
</l2Node>
<minitestId>4</minitestId>
<minitestName>Four</minitestName>
</minitest_root>',
'Valid - multiple l2Node elements');
INSERT INTO ZZZ_MINITEST_CLOB VALUES (
50,
'<minitest_root>
<l2Node>
<l2Num>1</l2Num>
<l2Name>five.one</l2Name>
</l2Node>
<l2Node>
<l2Num>2</l2Num>
<l2Name>five.two</l2Name>
</l2Node>
<minitestId>4</minitestId>
<minitestName>Five</minitestName>
<!-- another l2Node node, but too far down -->
<l2Node>
<l2Num>3</l2Num>
<l2Name>five.three</l2Name>
</l2Node>
</minitest_root>',
'Invalid - another l2Node node, but too far down');
INSERT INTO ZZZ_MINITEST_CLOB VALUES (
60,
'something that is not even xml',
'Invalid - something that is not even xml');
INSERT INTO ZZZ_MINITEST_CLOB VALUES (
70,
NULL,
'Invalid - good old NULL');
INSERT INTO ZZZ_MINITEST_CLOB VALUES (
80,
'<minitest_root>
<l2Node>
<l2Num>1</l2Num>
<l2Name>
<unexpected_node>
this one should not be here!
</unexpected_node>
</l2Name>
</l2Node>
<minitestId>8</minitestId>
<minitestName>Eight</minitestName>
</minitest_root>',
'Invalid - unexpected addl node');
INSERT INTO ZZZ_MINITEST_CLOB VALUES (
90,
'<something> that has tags but is no xml </either>',
'Invalid - something that has tags but is no xml either');
COMMIT;
Next I register the XSD...
BEGIN
DBMS_XMLSCHEMA.REGISTERSCHEMA(
'http://localhost/minitest.xsd',
'<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:oraxdb="http://xmlns.oracle.com/xdb" oraxdb:storeVarrayAsTable="true" oraxdb:schemaURL="http://localhost/minitest.xsd">
<xs:element name="minitest_root" oraxdb:SQLName="MINITEST_ROOT" oraxdb:SQLType="MINITEST_TYPE" oraxdb:defaultTable="" oraxdb:tableProps="NOLOGGING" oraxdb:maintainDOM="false">
<xs:complexType oraxdb:SQLType="MINITEST_TYPE" oraxdb:maintainDOM="false">
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="l2Node" oraxdb:SQLName="L2_NODE" oraxdb:SQLType="L2_NODE_TYPE" oraxdb:SQLCollType="L2_NODE_COLL" oraxdb:maintainDOM="false"/>
<xs:element ref="minitestId" oraxdb:SQLName="MINITEST_ID" oraxdb:SQLType="NUMBER" oraxdb:maintainDOM="false"/>
<xs:element ref="minitestName" oraxdb:SQLName="MINITEST_NAME" oraxdb:SQLType="VARCHAR2" oraxdb:maintainDOM="false"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="l2Node" oraxdb:SQLName="L2_NODE" oraxdb:SQLType="L2_NODE_TYPE" oraxdb:defaultTable="" oraxdb:tableProps="TABLESPACE CATALOG NOLOGGING" oraxdb:maintainDOM="false">
<xs:complexType oraxdb:SQLType="L2_NODE_TYPE" oraxdb:maintainDOM="false">
<xs:sequence>
<xs:element ref="l2Num" oraxdb:SQLName="L2_NUM" oraxdb:SQLType="NUMBER" oraxdb:maintainDOM="false"/>
<xs:element ref="l2Name" oraxdb:SQLName="L2_NAME" oraxdb:SQLType="VARCHAR2" oraxdb:maintainDOM="false"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="l2Num" type="number10_0Type" oraxdb:SQLName="L2_NUM" oraxdb:SQLType="NUMBER" oraxdb:maintainDOM="false" />
<xs:element name="l2Name" type="varchar100Type" oraxdb:SQLName="L2_NAME" oraxdb:SQLType="VARCHAR2" oraxdb:maintainDOM="false" />
<xs:element name="minitestId" type="number10_0Type" oraxdb:SQLName="MINITEST_ID" oraxdb:SQLType="NUMBER" oraxdb:maintainDOM="false" />
<xs:element name="minitestName" type="varchar100Type" oraxdb:SQLName="MINITEST_NAME" oraxdb:SQLType="VARCHAR2" oraxdb:maintainDOM="false" />
<xs:simpleType name="varchar100Type">
<xs:restriction base="xs:string">
<xs:maxLength value="100"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="number10_0Type">
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>',
GENTABLES=>FALSE
END;
And then I create my XML tables - four different ones for four different test cases. I am trying unstructured binary XML and strucured OR-based XML, each with and without a trigger.
One with structured OR storage and no trigger
CREATE TABLE ZZZ_MINITEST_ORXML (
ID NUMBER(10,0) NOT NULL ENABLE,
XML_CONTENT XMLTYPE,
CONSTRAINT PK_ZZZ_MINITEST_ORXML PRIMARY KEY (ID)
) NOLOGGING
VARRAY "XML_CONTENT"."XMLDATA"."L2_NODE" STORE AS TABLE "ZZZ_OR_L2_NODE" (NOLOGGING) RETURN AS LOCATOR
XMLTYPE XML_CONTENT STORE AS OBJECT RELATIONAL XMLSCHEMA "http://localhost/minitest.xsd" ELEMENT "minitest_root";
One with structured OR storage which will also have a trigger added further down
CREATE TABLE ZZZ_MINITEST_ORXML_TRGR (
ID NUMBER(10,0) NOT NULL ENABLE,
XML_CONTENT XMLTYPE,
CONSTRAINT PK_ZZZ_MINITEST_ORXML_TRGR PRIMARY KEY (ID)
) NOLOGGING
VARRAY "XML_CONTENT"."XMLDATA"."L2_NODE" STORE AS TABLE "ZZZ_OR_L2_NODE_TRGR" (NOLOGGING) RETURN AS LOCATOR
XMLTYPE XML_CONTENT STORE AS OBJECT RELATIONAL XMLSCHEMA "http://localhost/minitest.xsd" ELEMENT "minitest_root";
One with unstructured binary XML in a SECUREFILE, no trigger
CREATE TABLE ZZZ_MINITEST_BINXML_TRGR (
ID NUMBER(10,0) NOT NULL ENABLE,
XML_CONTENT XMLTYPE,
CONSTRAINT PK_ZZZ_MINITEST_BINXML_TRGR PRIMARY KEY (ID)
) NOLOGGING
XMLTYPE COLUMN XML_CONTENT STORE AS SECUREFILE BINARY XML
(NOCOMPRESS NOCACHE NOLOGGING KEEP_DUPLICATES);
One with unstructured binary XML in a SECUREFILE, which will also have a trigger
CREATE TABLE ZZZ_MINITEST_BINXML (
ID NUMBER(10,0) NOT NULL ENABLE,
XML_CONTENT XMLTYPE,
CONSTRAINT PK_ZZZ_MINITEST_BINXML PRIMARY KEY (ID)
) NOLOGGING
XMLTYPE COLUMN XML_CONTENT STORE AS SECUREFILE BINARY XML
(NOCOMPRESS NOCACHE NOLOGGING KEEP_DUPLICATES);
Then I create the error logging tables
begin
DBMS_ERRLOG.CREATE_ERROR_LOG ('ZZZ_MINITEST_BINXML', 'ZZZ_MINITEST_BINXML_E', NULL, NULL, TRUE);
DBMS_ERRLOG.CREATE_ERROR_LOG ('ZZZ_MINITEST_BINXML_TRGR', 'ZZZ_MINITEST_BINXML_TRGR_E', NULL, NULL, TRUE);
DBMS_ERRLOG.CREATE_ERROR_LOG ('ZZZ_MINITEST_ORXML', 'ZZZ_MINITEST_ORXML_E', NULL, NULL, TRUE);
DBMS_ERRLOG.CREATE_ERROR_LOG ('ZZZ_MINITEST_ORXML_TRGR', 'ZZZ_MINITEST_ORXML_TRGR_E', NULL, NULL, TRUE);
END;
Now the two triggers
create or replace trigger TRG_ZZZ_MINITEST_BINXML
BEFORE UPDATE OR INSERT ON ZZZ_MINITEST_BINXML_TRGR
REFERENCING NEW AS NEW
for each row
BEGIN
:NEW.XML_CONTENT := :NEW.XML_CONTENT.createSchemaBasedXML('http://localhost/minitest.xsd');
:NEW.XML_CONTENT.SCHEMAVALIDATE();
END TRG_ZZZ_MINITEST_BINXML;
CREATE OR REPLACE TRIGGER TRG_ZZZ_MINITEST_ORXML
BEFORE UPDATE OR INSERT ON ZZZ_MINITEST_ORXML_TRGR
REFERENCING NEW AS NEW
for each row
BEGIN
:NEW.XML_CONTENT := :NEW.XML_CONTENT.createSchemaBasedXML('http://localhost/minitest.xsd');
:NEW.XML_CONTENT.SCHEMAVALIDATE();
END TRG_ZZZ_MINITEST_ORXML;
I also tried to just validate the XML using queries such as the below, since validating all without the WHERE also caused exception and abortion:
SELECT ID, DECODE(XMLISVALID(XMLTYPE(XML_DOC), 'http://localhost/minitest.xsd'), 1, 'Y', 0, 'N', '?') VALID
FROM ZZZ_MINITEST_CLOB WHERE ID=90;
The results are in column "VALID" in the below tables
I tried inserting all records from ZZZ_MINITEST_CLOB into the four test tables at once using a query such as
INSERT INTO ZZZ_MINITEST_ORXML_TRGR
SELECT ID, XMLPARSE(DOCUMENT XML_DOC WELLFORMED) FROM ZZZ_MINITEST_CLOB
LOG ERRORS INTO ZZZ_MINITEST_ORXML_TRGR_E REJECT LIMIT UNLIMITED;
I also tried different versions of creating the XML in the SELECT portion:
XMLPARSE(DOCUMENT XML_DOC WELLFORMED)
XMLPARSE(DOCUMENT XML_DOC WELLFORMED)
XMLTYPE(XML_DOC)
XMLTYPE(XMLDOC, 'http://localhost/minitest.xsd', 0, 1)
Almost all combinations of the four test tables with the four ways to instantiate the XML caused exceptions and query abortion despite the LOG ERRORS INTO clause.
In order to find the exact problems, I started inserting records one by one using queries like
INSERT INTO ZZZ_MINITEST_ORXML
SELECT ID, XMLPARSE(DOCUMENT XML_DOC) FROM ZZZ_MINITEST_CLOB WHERE ID=10
LOG ERRORS INTO ZZZ_MINITEST_ORXML_E REJECT LIMIT UNLIMITED;
or
INSERT INTO ZZZ_MINITEST_BINXML_TRGR
SELECT ID, XMLTYPE(XMLDOC, 'http://localhost/minitest.xsd', 0, 1) FROM ZZZ_MINITEST_CLOB WHERE ID=20
LOG ERRORS INTO ZZZ_MINITEST_BINXML_TRGR_E REJECT LIMIT UNLIMITED;
I captured the results of each in the below four tables. "1" and "0" are number of rows inserted. 0 means there was no record inserted and instead, there was an error logged in the ERROR LOGGING table.
The ORA-????? exception numbers mean that this error actually caused the INSERT to fail and abort rather than just being logged in the LOGGING TABLE.These are the most critical cases for me. Why do these exceptions "bubble up" forcing the query to be aborted rather than being logged in the error log as well???
This table is for INSERT of XMLs using XMLTYPE(XML_DOC)
Test case
VALID
Binary XML,
no trigger
Binary XML,
trigger
OR XML,
no trigger
OR XML,
trigger
10
Good
Y
1
1
1
1
20
no name
N
1
0
1
0
30
switched tags
N
1
1
1
1
40
Good
Y
1
1
1
1
50
L2 down
N
1
1
1
1
60
no xml
EX
ORA-31011
ORA-31011
ORA-31011
ORA-31011
70
NULL
EX
ORA-06502
ORA-06502
ORA-06502
ORA-06502
80
addl. Node
N
1
0
ORA-31187
ORA-31187
90
crappy xml
EX
ORA-31011
ORA-31011
ORA-31011
ORA-31011
This table is for INSERT of XMLs using XMLTYPE(XML_DOC, 'http://localhost/minitest.xsd', 0, 1)
Test case
VALID
Binary XML,
no trigger
Binary XML,
trigger
OR XML,
no trigger
OR XML,
trigger
10
Good
Y
1
1
1
1
20
no name
N
1
0
1
0
30
switched tags
N
1
1
1
1
40
Good
Y
1
1
1
1
50
L2 down
N
1
1
1
1
60
no xml
EX
ORA-31043
ORA-31043
ORA-31043
ORA-31043
70
NULL
EX
ORA-06502
ORA-06502
ORA-06502
ORA-06502
80
addl. Node
N
1
0
ORA-31187
ORA-31187
90
crappy xml
EX
ORA-31043
ORA-31043
ORA-31043
ORA-31043
This table is for INSERT of XMLs using XMLPARSE(DOCUMENT XML_DOC WELLFORMED)
Test case
VALID
Binary XML,
no trigger
Binary XML,
trigger
OR XML,
no trigger
OR XML,
trigger
10
Good
Y
1
1
1
1
20
no name
N
1
0
1
0
30
switched tags
N
1
1
1
1
40
Good
Y
1
1
1
1
50
L2 down
N
1
1
1
1
60
no xml
ORA-31061
0
ORA-31011
ORA-31011
70
NULL
1
0
1
0
80
addl. Node
N
0
0
ORA-31187
ORA-31187
90
crappy xml
ORA-31061
0
ORA-30937
ORA-30937
This table is for INSERT of XMLs using XMLPARSE(DOCUMENT XML_DOC) (same as above, but without "WELLFORMED")
Test case
VALID
Binary XML,
no trigger
Binary XML,
trigger
OR XML,
no trigger
OR XML,
trigger
10
Good
Y
1
1
1
1
20
no name
N
1
0
1
0
30
switched tags
N
1
1
1
1
40
Good
Y
1
1
1
1
50
L2 down
N
1
1
1
1
60
no xml
ORA-31011
ORA-31011
ORA-31011
ORA-31011
70
NULL
1
0
1
0
80
addl. Node
N
1
0
ORA-31187
ORA-31187
90
crappy xml
ORA-31011
ORA-31011
ORA-31011
ORA-31011
As you can see, different ways to instantiate the XML which is being inserted will cause different results for the most critical cases (60, 80 and 90). One will go through with an error logged in the logging table and no record inserted, others cause exceptions. Also, using XMLPARSE with or without WELLFORMED causes different ORA numbers for record 90...
It seems like the only way to not get any exceptions for my test records is inserting XMLs that were created using XMLPARSE (DOCUMENT ... WELLFORMED) into the trigger-protected binary XML table. However, that causes me to miss record number 80, which is one that I really need, because it is well formed and I could use XSLTs to fix the XML by removing the extra tags, as long as I know which ones those are. -
How to validate an xml with a schema w/o specifying the schema in the xml
I have done xml validation with xml schemas, where the xml points to the xsd to use. However, I would like to not have to specifiy the xml schema in the xml document (and can't ensure that the xml coming to us has that in it). How do I, in the java code, tell it what schema to use in validation?
Brianstatic final String schemaSource = argv[0];
static final String JAXP_SCHEMA_SOURCE =
"http://java.sun.com/xml/jaxp/properties/schemaSource";
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setAttribute(JAXP_SCHEMA_SOURCE,
new File(schemaSource)); -
hello
trying to write a unit test that validates some xml we are marshalling against a dtd. here is a snippet of code. The problem is how to specify the dtd against which the xml is to be validated. verification_transaction is our root xml element. when i run this code i get a
malformedurlexception: no protocol: verification.dtd
any ideas?
StringWriter writer = new StringWriter();
// write the doctype declaration
writer.write("<!DOCTYPE verification_transaction SYSTEM \"verification.dtd\">");
// now marshal to the writer
marshaller.marshal(spec, requestType, componentNumber, writer);
InputStream inputStream = new ByteArrayInputStream(writer.getBuffer().toString().getBytes());
Reader reader = new InputStreamReader(inputStream);
// get a sax parser that is validating
TestHandler handler = new TestHandler();
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
SAXParser saxParser = factory.newSAXParser();
try {
saxParser.parse(new InputSource(reader), handler);
fail("Should have thrown exception.");
} catch (RuntimeException e) {
// pass
}Message was edited by:
shrndegruvI needed to do a bunch of things.
1.
URL url = getClass().getResource("/verification.dtd");
StringWriter writer = new StringWriter();
writer.write("<?xml version=\"1.0\"?><!DOCTYPE verification_transaction SYSTEM \"" + url + "\">");and then I had to use a handler which processed the errors (which I got from an online tutorial):
private static class MyErrorHandler extends DefaultHandler {
public void warning(SAXParseException e) throws SAXException {
System.out.println("Warning: ");
printInfo(e);
public void error(SAXParseException e) throws SAXException {
System.out.println("Error: ");
printInfo(e);
throw new SAXException("DTD Validation Error: [" + e.getMessage() + "]");
public void fatalError(SAXParseException e) throws SAXException {
System.out.println("Fatal error: ");
printInfo(e);
private void printInfo(SAXParseException e) {
System.out.println(" Public ID: " + e.getPublicId());
System.out.println(" System ID: " + e.getSystemId());
System.out.println(" Line number: " + e.getLineNumber());
System.out.println(" Column number: " + e.getColumnNumber());
System.out.println(" Message: " + e.getMessage());
} -
Validating relationships with external objects
Hi
I am working with the ICM (Incentive and Commission Management) module and i type the transaction code PPOME. Ive got an external organisation defined and i want to add a Business Partner. Now before adding that partner, i would like to know if there is a user exit that can be used during or after the addition of the BP.
I would like to use this exit to compare the start and end dates for two (2) entries in the HRP1001 table. It is to enforce a validation of relationship dates during the maintenance of a relationship between an Org object and a BP or external object.Any pointers would be greatly appreciated.
Regards
Simba
Edited by: Lovemore Mandimika on May 6, 2008 12:34 PMThank you for replying Mr Goris. Im still very new to SAP and ICM so can you provide more context into how i can go about implementing the user exit for info type HRP 1001. Thank you for your time.
Regards
Simba -
How to bind dynamic xml with Java objects without xsd
have a question, and hope someone here can help me.
In my current project, I will get a xml file, containing some information of each user, and map them into a set of user objects.
For each user, there are some fixed attributes, such as name, phone#, age, position, etc. The problem is, client can customize, and add new attibutes, such as address, favorite color, so there will be no xsd for the xml.
What I want to do, is map fixed attributes to user object attributes, for example, name attribute to User.name, and they will have corresponding getters, and setters, but for custom attributes, I want to add them to a HashMap in User object, for example, use string "ADDRESS" as the key, and address as the value.
Is there any way I can do this? Thank you very much for any help you can provide.It would not be too hard to do in regular code.
First, make a HashSet with the Strings for the names of the known attributes that will be processed with setters.
Then, get the NamedNodeMap via getAttributes(). That will give you all attributes -- both the ones you will handle with your setters and the ones you will handle via a HashMap.
Then, loop through the NamedNodeMap. For each attribute, get the name and value. If the name is in the HashSet of known values, process it with a list of
if ( attName.equals( "name" ))
whatever.setName( value );
continue;
}If it is not in the HashSet, then set the value into your HashMap with the name and value.
There is no standard way to do this.
Dave Patterson -
Validate xml with complextype schema without root element!
Hi All!
I have a problem that. I want to validate a xml data of complextype but the schema i want to validate is[b] not have root element.
For example:
The schema like that
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="www.thachpn.test" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="www.thachpn.test" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="Name">
<xs:sequence>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
and the xml data i want to validate like this
<?xml version="1.0" encoding="UTF-8"?>
<Name xmlns="www.thachpn.test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FirstName>Pham</FirstName>
<LastName>Thach</LastName>
</Name>
My Algorithm is like that:
I create a complextype object by above schema
then i create new element with given name and namespace
after that i use schema of this element to validate xml data.
I use xmlparserv2 lib of oracle
But i can not find how to create complextype from schema or create element with have complextype.
Please help me.
Thanks a lot!<?xml version="1.0" encoding="UTF-8"?>
Modify the schema.
Add a root element.
<xs:schema targetNamespace="www.thachpn.test" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="www.thachpn.test" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="Name" type="Name"/>
<xs:complexType name="Name">
<xs:sequence>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema> -
Validating an XML document using external DTD?
Hi,
I want to validate an XML file using external DTD with SAX parser.
How can I validate an XML file with external DTD.
Thanks in Advance,
MahendraI dont think we can set a DTD file throug java while
parsing an XML.I've done it with an XML schema though. Can you use that instead? For schemas you do something like:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaSource",
schemaUrl );where schemaUrl in this case would be something like file:///usr/local/whatever.xsd -
Force to validate external DTD ?
Hello everybody !
Actually I parse a XML document with validation feature turned on :
XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setContentHandler(myHandler);
parser.setErrorHandler(myHandler);
parser.parse("/XMLdoc/.../myDoc.xml");
DTD reference is specified in XML document :
<?xml version="1.0" standalone="no"?>
<!DOCTYPE root SYSTEM "file.dtd">
Does anybody know how to force XML validation according to external DTD not define in the document at parse time (I want user to make its own XML document without reference or handling DTD part) ?
Thanks for your help !Then I'd recommend processing the file with DOM without validation, creating a second Document object with the proper DTD specified (or enough of it specified that you could supply the rest via an EntityResolver) and then copy the contents of the full Document into the new Document with no contents but with a good DTD.
Then, serialize it to a stream or String, and run it throught DOM a second time.
Kind of clunky, but it should work unless the file is huge.
If the file is huge, I'd write code to read the file as a character stream and put the DTD specificaiton in the data. Then process this modified version through DOM.
Dave Patterson
Maybe you are looking for
-
How do I choose which movies to load into my ipad from my itunes library? Seems like everytime I sync, it loads up all the movies I have in my itunes library.
-
Sharing file paths on server via email
Basic question, using either Entourage or Mail.app is it possible to provide a hyperlink to a document located on a leopard server share? thanks
-
Hi All, We have a CAD server installed on ICM PG box. Two agent location namely X and Y Datacenter resided in location X Users in location X were not facing any issue Users from location Y facing diificulties and they were using CAD ver 7.5.1. Random
-
Safari 3.1.2 will not fully load iWeb pages
After updating to Mac OS 10.4.11 and Safari 3.1.2 my iWeb website will not load without errors which leave the graphics blank. The Activity window says they are timed out errors. Prior to this my web site loaded fine. I can open it in FireFox and Int
-
Hi, while I used VS2010 to develop crystal report . It asks user name and password after compile. But i create a service based database.