Benjamin Keil | 1 May 2006 03:54

Validating a document against a schema that contains inline SVGs

Hello all,

  I'm trying to put together a schema that would allow inline SVG
elements, but I'm having a lot of trouble making this work.

The main problem seems to be coming from the SVG schema
(from http://www.w3.org/TR/2002/WD-SVG11-20020108/SVG.xsd )

I am loading documents like this:

DocumentBuilderFactory factory = new
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl();
factory.setFeature("http://apache.org/xml/features/validation/schema",
true);
factory.setFeature("http://xml.org/sax/features/validation", true);	
factory.setFeature("http://xml.org/sax/features/namespaces", true);
factory.setNamespaceAware(true);

DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(source);

Even trying to validate a little document like this:

<?xml version="1.0" encoding="UTF-8"?>
<svg:svg height="10cm" width="11cm" viewBox="0 0 1100 1000"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.w3.org/2000/svg svg.xsd ">

	<svg:rect x="1" y="1" width="1098" height="998" fill="none"
(Continue reading)

Michael Glavassevich | 1 May 2006 04:44
Picon

Re: Validating a document against a schema that contains inline SVGs

Benjamin Keil <bkeil <at> humnet.ucla.edu> wrote on 04/30/2006 09:54:01 PM:

> Hello all,
> 
>   I'm trying to put together a schema that would allow inline SVG
> elements, but I'm having a lot of trouble making this work.
> 
> The main problem seems to be coming from the SVG schema
> (from http://www.w3.org/TR/2002/WD-SVG11-20020108/SVG.xsd )

This schema document has a DTD (XMLSchema.dtd) which references another 
document (datatypes.dtd) that doesn't exist at the specified location. The 
working draft of SVG [1] you're using says: "this schema is still in 
development and is being tested" so it's possible there were other 
problems with this version.

error: Parse error occurred - 
http://www.w3.org/TR/2002/WD-SVG11-20020108/datatypes.dtd
java.io.FileNotFoundException: 
http://www.w3.org/TR/2002/WD-SVG11-20020108/datatypes.dtd
        at 
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:682)
        at 
org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:959)
        at 
org.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:871)
        at 
org.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:809)
        at 
org.apache.xerces.impl.XMLDTDScannerImpl.startPE(XMLDTDScannerImpl.java:640)
(Continue reading)

Prashant | 1 May 2006 06:13

Re: Validating a document against a schema that contains inline SVGs


>Hello all,
>
><snip>
>
>I am loading documents like this:
>
>DocumentBuilderFactory factory = new
>org.apache.xerces.jaxp.DocumentBuilderFactoryImpl();
>factory.setFeature("http://apache.org/xml/features/validation/schema",
>true);
>factory.setFeature("http://xml.org/sax/features/validation", true);	
>factory.setFeature("http://xml.org/sax/features/namespaces", true);
>factory.setNamespaceAware(true);
>
>DocumentBuilder builder = factory.newDocumentBuilder();
>Document doc = builder.parse(source);
>
>Even trying to validate a little document like this:
>
><?xml version="1.0" encoding="UTF-8"?>
><svg:svg height="10cm" width="11cm" viewBox="0 0 1100 1000"
>xmlns:svg="http://www.w3.org/2000/svg"
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>	xsi:schemaLocation="http://www.w3.org/2000/svg svg.xsd ">
>
>	<svg:rect x="1" y="1" width="1098" height="998" fill="none"
>stroke="blue" stroke-width="2" />
>
></svg:svg>
(Continue reading)

Prashant | 1 May 2006 06:17

Re: Validating a document against a schema that contains inline SVGs

Oops!

    xsi:schemaLocation="http://www.w3.org/2000/svg svg.xsd

does contain the schema location hint and target namespace. I should 
have been paying more attention. :)

-Prashant

Prashant wrote:

>
>> Hello all,
>>
>> <snip>
>>
>> I am loading documents like this:
>>
>> DocumentBuilderFactory factory = new
>> org.apache.xerces.jaxp.DocumentBuilderFactoryImpl();
>> factory.setFeature("http://apache.org/xml/features/validation/schema",
>> true);
>> factory.setFeature("http://xml.org/sax/features/validation", true);   
>> factory.setFeature("http://xml.org/sax/features/namespaces", true);
>> factory.setNamespaceAware(true);
>>
>> DocumentBuilder builder = factory.newDocumentBuilder();
>> Document doc = builder.parse(source);
>>
>> Even trying to validate a little document like this:
(Continue reading)

Jeff.Barton | 2 May 2006 18:58
Favicon

NullPointerException when calling Document.importNode(Node importedNode,boolean deep)

I’m hoping someone can give me some insight to an issue that is currently stalling a development project. In summary, I need to insert a pre-existing XML document fragment in to another XML document. I have tried to do this insertion by first using the importNode() operation on the org.w3c.dom.Document interface followed by an appendChild() operation from the org.w3c.dom.Node interface on the new owner document. When I attempt these operations I receive a NullPointException that is being generated by an underlying Xerces implementation. The code below generates the Exception:

 

 

            public void insertNode(SOAPMessage message, Context context)

            {

                        // This is the Node that needs to be inserted in the new “Owner” document. The content of the node can be seen below

Node wsseNode = (Node)sessionContext.getSessionAttribute(ISessionContext.WSSE_NODE_KEY);

                       

                        // This Node is present and this print statement never executes

                        if (wsseNode == null)

                                    System.out.println(ErrorFormatter.formatLogMessage(this.getClass(),"wsse:Security Node IS NULL",ErrorFormatter.ERROR));

                        else

                        {

                                    Node importedNode = null;

 

                                    // soapMessage is not null and the following code block always executes

                                   

if (message != null)

                                    {

                                                Element header = message.getHeader();

                                                if (header == null)

                                                            header = message.addHeader();

 

                                                Document doc = message.getDocument();

                                                try

                                                {

                                                            // this call generates the NullPointException. The wsseNode is not null and its presence has been verified by multiple means

                                                            // the method never proceeds beyond this point.

 

ImportedNode = doc.importNode(wsseNode,true);

                                                }

                                                catch (DOMException de)

                                                {System.out.println(ErrorFormatter.formatErrorMessage(this.getClass(),de));}

 

                                                header.appendChild(importedNode);

                                    }

                                 else

                                                System.out.println(ErrorFormatter.formatLogMessage(this.getClass(),"SOAPMessage IS NULL",ErrorFormatter.ERROR));

                        }

            }

 

 

 

 

 

This is the resulting stack trace:

 

Exception in thread "main" java.lang.NullPointerException

        at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source)

        at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source)

        at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source)

        at com.gxs.common.webservice.security.SAMLSerializationInterceptor.intercept(SAMLSerializationInterceptor.java:61)

        at electric.soap.util.SOAPInterceptors.callInterceptors(Unknown Source)

        at electric.soap.references.interceptor.InterceptorSOAPReference.handle(Unknown Source)

        at electric.soap.java.reference.JavaToSOAP.handle(Unknown Source)

        at electric.soap.java.reference.JavaToSOAP.invoke(Unknown Source)

        at electric.soap.java.reference.JavaToSOAP.invoke(Unknown Source)

        at electric.proxy.handler.Proxy.invoke(Unknown Source)

        at $Proxy0.testProcess(Unknown Source)

        at com.gxs.saml.test.SAMLTestClient.<init>(SAMLTestClient.java:54)

        at com.gxs.saml.test.SAMLTestClient.main(SAMLTestClient.java:66)

 

 

 

 

The XML Node that I’m trying to insert is:

 

<wsse:Security xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>

                <saml:Assertion AssertionID='id-5a344e56a77d5f8b88fba7adf1a5e9578edf3cec' IssueInstant='2006-04-05T19:40:00.869Z' Issuer='http://www.forumsys.com/sentry' MajorVersion='1' MinorVersion='1' xmlns:saml='urn:oasis:names:tc:SAML:1.0:assertion'>

                                <saml:Conditions NotBefore='2006-04-05T19:40:00.869Z' NotOnOrAfter='2006-04-05T19:41:00.869Z'></saml:Conditions>

                                <saml:AuthenticationStatement AuthenticationInstant='2006-04-05T19:40:00.869Z' AuthenticationMethod='urn:oasis:names:tc:SAML:1.0:am:password'>

                                                <saml:Subject>

                                                                <saml:NameIdentifier Format='urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName'>  1.2.840.113549.1.9.1=#16167062656e656e736f6e40666f72756d7379732e636f6d,CN=Pasha Benenson,C=US</saml:NameIdentifier>

                                                                <saml:SubjectConfirmation>

                                                                                <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:sender-vouches</saml:ConfirmationMethod>

                                                                </saml:SubjectConfirmation>

                                                </saml:Subject>

                                                <saml:SubjectLocality IPAddress='10.160.37.108'></saml:SubjectLocality>

                                </saml:AuthenticationStatement>

                                <saml:AttributeStatement>

                                                <saml:Subject>

                                                                <saml:NameIdentifier Format='urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName'>1.2.840.113549.1.9.1=#16167062656e656e736f6e40666f72756d7379732e636f6d,CN=Pasha Benenson,C=US</saml:NameIdentifier>

                                                                <saml:SubjectConfirmation>

                                                                                <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:sender-vouches</saml:ConfirmationMethod>

                                                                </saml:SubjectConfirmation>

                                                </saml:Subject>

                                                <saml:Attribute AttributeName='IM_UserID' AttributeNamespace='http://www.forumsys.com/sentry'>

                                                                <saml:AttributeValue>GCP4444449999</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute AttributeName='IM_FirstName' AttributeNamespace='http://www.forumsys.com/sentry'>

                                                                <saml:AttributeValue>Donald</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute AttributeName='IM_MiddleInitials' AttributeNamespace='http://www.forumsys.com/sentry'>

                                                                <saml:AttributeValue>M</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute AttributeName='IM_LastName' AttributeNamespace='http://www.forumsys.com/sentry'>

                                                                <saml:AttributeValue>Duck</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute AttributeName='IM_BUID' AttributeNamespace='http://www.forumsys.com/sentry'>

                                                                <saml:AttributeValue>GC7777888888</saml:AttributeValue></saml:Attribute>

                                                <saml:Attribute AttributeName='IM_PreferredLanguage' AttributeNamespace='http://www.forumsys.com/sentry'>

                                                                <saml:AttributeValue>en</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute AttributeName='IM_TimeZone' AttributeNamespace='http://www.forumsys.com/sentry'>

                                                                <saml:AttributeValue>America/Los Angelos</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute AttributeName='IM_UserEmail' AttributeNamespace='http://www.forumsys.com/sentry'>

                                                                <saml:AttributeValue>donald.duck <at> disney.com</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute AttributeName='IM_Country' AttributeNamespace='http://www.forumsys.com/sentry'>

                                                                <saml:AttributeValue>US</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute AttributeName='IM_CommunityID' AttributeNamespace='http://www.forumsys.com/sentry'>

                                                                <saml:AttributeValue>GCM65405</saml:AttributeValue>

                                                </saml:Attribute>

                                </saml:AttributeStatement>

                                <saml:AuthorizationDecisionStatement Decision='Permit' Resource='WebService_Authorization'>

                                                <saml:Subject>

                                                                <saml:NameIdentifier Format='urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName'>1.2.840.113549.1.9.1=#16167062656e656e736f6e40666f72756d7379732e636f6d,CN=Pasha Benenson,C=US</saml:NameIdentifier>

                                                                <saml:SubjectConfirmation>

                                                                                <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:sender-vouches</saml:ConfirmationMethod>

                                                                </saml:SubjectConfirmation>

                                                </saml:Subject>

                                                <saml:Action Namespace='urn:oasis:names:tc:SAML:1.0:action:rwedc-negation'>Execute</saml:Action>

                                </saml:AuthorizationDecisionStatement>

                </saml:Assertion>

 </wsse:Security>

 

 

 

Are there limitations to the complexity of the Node that you can import? I tried the import operation with a simple parent/single child xml document and the import() operation worked successfully.

Am I using the importNode() operation in an inappropriate way?

If so, what are my alternatives for inserting an xml fragment from one document to another?

If not, what changes do I need to make to accomplish this activity?

 

I am using the xml-apis.jar and xercesImpl.jar files from the 2.7 release of Xalan.

 

Thanks in advance for any help!

 

Jeff

Joseph Kesselman | 2 May 2006 20:30
Picon
Favicon

Re: NullPointerException when calling Document.importNode(Node importedNode,boolean deep)

You might want to try running this under a debugger to see what field is
actually coming up as null. I'd be inclined to suspect that the node you're
importing from is damaged and/or otherwise isn't properly implementing the
DOM APIs, hence is returning null at a time when null isn't expected.

If not, then we may have a bug in the importNode implementation. But
determining exactly what's failing is the first step in determining whether
the problem is in the source DOM or sink DOM.

______________________________________
"... Three things are most perilous: Connectors that corrode,
  Unproven algorithms, and self-modifying code! ..."
  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish
(http://www.ovff.org/pegasus/songs/threes-rev-11.html)
Crain, David B. (LNG-DAY | 5 May 2006 21:54
Favicon

I am currently having a problem with entities in a DOM Parser

Code:

                        domParser.setFeature(“http://apache.org/xml/features/validation/schema”, false);

                        domParser.setFeature(“http://apache.org/xml/features/dom/create-entity-ref-nodes”, false);

 

With this configuration, and using Xerces 2.2.1, anytime the parser encounters an entity that is not defined in the DTD, we get the following results:

Input:                properly elected to do so, can amend its &bogus; Federal income tax returns filed

Output:             Federal income tax returns filed

 

Ran a test with a newer version of Xerces (2.6.0) and got a slightly different result:

Input:                properly elected to do so, can amend its &bogus; Federal income tax returns filed

Output:             properly elected to do so, can amend its  Federal income tax returns filed

 

In either case, this is not a good thing.

 

I am looking for method that would allow me to keep the above features set the way they are, but code a method that would allow me identify an undefined entity in the data.

 

I am also curious why the Xerces code would not throw an exception when the above data is encountered. I am will to go to 2.8.0 Xerces if this problem was addressed.

 

Let me re-state, I want the code to throw an exception!!!!

 

Please let me know if there are any questions.

 

Dave

 

David B. Crain
Consultant Software Engineer
Editorial & Conversion Systems
Lexis-Nexis
Phone: 937-865-6800 ext. 56303

 

Michael Glavassevich | 6 May 2006 20:04
Picon

Re: I am currently having a problem with entities in a DOM Parser

Dave,

A reference to an undeclared entity isn't always a well-formedness error 
[1]. I suspect your document has an external DTD, in which case you need 
to enable DTD validation and register an error handler to be notified that 
your document references an undeclared entity [2]. You can throw an 
exception from your error handler if you want the parser to stop.

Thanks.

[1] http://www.w3.org/TR/2004/REC-xml-20040204/#wf-entdeclared
[2] http://www.w3.org/TR/2004/REC-xml-20040204/#vc-entdeclared

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas <at> ca.ibm.com
E-mail: mrglavas <at> apache.org

"Crain, David B. \(LNG-DAY\)" <David.Crain <at> lexisnexis.com> wrote on 
05/05/2006 03:54:16 PM:

> Code:
>                         domParser.setFeature(?http://apache.
> org/xml/features/validation/schema?, false);
>                         domParser.setFeature(?http://apache.
> org/xml/features/dom/create-entity-ref-nodes?, false);
> 
> With this configuration, and using Xerces 2.2.1, anytime the parser 
> encounters an entity that is not defined in the DTD, we get the 
> following results:
> Input:                properly elected to do so, can amend its &bogus;
> Federal income tax returns filed
> Output:             Federal income tax returns filed
> 
> Ran a test with a newer version of Xerces (2.6.0) and got a slightly
> different result:
> Input:                properly elected to do so, can amend its &bogus
> ; Federal income tax returns filed
> Output:             properly elected to do so, can amend its 
> Federal income tax returns filed
> 
> In either case, this is not a good thing. 
> 
> I am looking for method that would allow me to keep the above 
> features set the way they are, but code a method that would allow me
> identify an undefined entity in the data. 
> 
> I am also curious why the Xerces code would not throw an exception 
> when the above data is encountered. I am will to go to 2.8.0 Xerces 
> if this problem was addressed. 
> 
> Let me re-state, I want the code to throw an exception!!!!
> 
> Please let me know if there are any questions. 
> 
> Dave 
> 
> David B. Crain 
> Consultant Software Engineer 
> Editorial & Conversion Systems 
> Lexis-Nexis 
> Phone: 937-865-6800 ext. 56303
Kopic Benjamin | 8 May 2006 15:35

Offline validation works on MS Windows but fails under Linux

Hi
 
We use Xerces J 2.7.1 to process XML files that validate against XML Schemata. However, the offline validation fails when run on Linux, although it works fine under MS Windows 2000. The API we use is dom4j (http://www.dom4j.org/) and JAXP, but I doubt that the problem is in those APIs.
 
This is the code snippet that does the validation:
 
 
reader.setXMLReaderClassName("org.apache.xerces.parsers.SAXParser");
reader.setFeature("http://apache.org/xml/features/validation/schema", true);
 
String mpdSchemaSource = System.getProperty("mpd-eph");
String messageheaderSchemaSource = System.getProperty("messageheader-eph");
 
 
try {
 // retrieve schemata as InputStream from CLASSPATH
 java.io.InputStream _mpd = getClass().getClassLoader().getResourceAsStream(mpdSchemaSource);
 java.io.InputStream _mh = getClass().getClassLoader().getResourceAsStream(messageheaderSchemaSource);
 java.io.InputStream[] _schemas = { _mpd, _mh };
 
 reader.setProperty(JAXP_SCHEMA_SOURCE, _schemas);
 reader.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
}
catch (Exception ex) {
 // log the error
}
 
reader.read(fileObj);
 
if (errorHandler.hasErrors()) {
 // not OK
 // always under Linux
}
else {
 // OK
 // always under MS Windows
}
 
 
The schemata are loaded correctly (I have verified that by outputing the InputStream objects to a file). One of the things we do, however, is using <xsd:import> to import "message-header" schema into "mpd" schema:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:mh="http://www.emea.eu.int/EuroPharm/1.0/message-header"
 xmlns:mpd="http://www.emea.eu.int/EuroPharm/1.0/mpd"
 targetNamespace="http://www.emea.eu.int/EuroPharm/1.0/mpd"
 elementFormDefault="qualified"
 attributeFormDefault="unqualified">
 
 <xsd:import schemaLocation="messageheader-eph-1.0.xsd" namespace="http://www.emea.eu.int/EuroPharm/1.0/message-header"/>
 
 <xsd:element name="mpd">
  <xsd:annotation>
   <xsd:documentation>This is a Dictionary feed file format....</xsd:documentation>
  </xsd:annotation>
  <xsd:complexType>
   <xsd:sequence>
    <xsd:element name="messageheader" type="mh:MessageHeader"/>
    <xsd:group ref="mpd:DictionaryEntriesGroup"/>
   </xsd:sequence>
  </xsd:complexType>
 </xsd:element>
 <!-- ... and the rest -->
 
 
The error I get is the following:
 
src-resolve: Cannot resolve the name 'mh:MessageHeader' to a(n) 'type definition' component.
schema_reference.4: Failed to read schema document 'file:///home/oracle/europharm/feed_ben/inbox/messageheader-eph-1.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not &lt;xsd:schema&gt;.
 
I suspect the problem is with this import directive in the schema definition, and the error message certainly points to it. The directory, /home/oracle/europharm/feed_ben/inbox/, is the location of XML files, while schemata are located in the CLASSPATH (in a JAR file).
 
Does anyone know how could I resolve this?
 
Best regards,
--
Benjamin Kopić
European Medicines Agency (EMEA)
IT Development - Communications & Networking
7 Westferry Circus
Canary Wharf
London
E14 4HB
Tel. +44(0)20 7523 7417
Fax. +44(0)20 7418 8669
benjamin.kopic <at> emea.eu.int
 

________________________________________________________________________
This e-mail has been scanned for all known viruses by EMEA.
________________________________________________________________________
Robert.A.Boesl | 8 May 2006 16:39
Favicon

Robert A Boesl/MMBI/HSBCAMERICAS is out of the office.


I will be out of the office starting  05/08/2006 and will not return until
05/09/2006.

B2G concerns please contact Becky Archambault at ext. 2002. All other
assistance contact Terry O'Shei at ext. 1165

-----------------------------------------
*******************************************************************
****
 This E-mail is confidential. It may also be legally privileged. If
you
 are not the addressee you may not copy, forward, disclose or use
any
 part of it. If you have received this message in error, please
delete
 it and all copies from your system and notify the sender
immediately
 by return E-mail.

 Internet communications cannot be guaranteed to be timely, secure,
 error or virus-free. The sender does not accept liability for any
 errors or omissions.
*******************************************************************
****

Gmane