You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Evaristo Jose Camarero (ML/EEM)" <ev...@ericsson.com> on 2005/03/09 10:13:26 UTC
DOM and NAMESPACES
Hi all:
I am using xml-beans 2 beta 1, and I am having problems with XMLBeans
DOM implementation and name spaces... In fact, the behaviour of the
library is different if I construct the XML from parameters, or I
construct it parsing a file or an stream.
A simple schema:
<?xml version="1.0" encoding="US-ASCII"?>
<schema
targetNamespace="http://www.apache.org/ns/#app1"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:apache="http://www.apache.org/ns/#app1"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
elementFormDefault="unqualified"
attributeFormDefault="unqualified"
version="1.0">
<import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/>
<element name="RootElement" type="apache:RootElementType"/>
<complexType name="RootElementType">
<sequence>
<element ref="ds:Signature" minOccurs="0"/>
</sequence>
<attribute name="ID" type="ID" use="required"/>
<attribute name="attr1" type="string" use="required"/>
<attribute name="attr2" type="string" use="required"/>
</complexType>
</schema>
Include the ds:Signature element (Digital Signature from Oasis)
If I use to create an XML message :
final RootElementDocument redoc =
RootElementDocument.Factory.newInstance();
RootElementType re = redoc.addNewRootElement();
re.setID("id1000");
re.setAttr1("test1");
re.setAttr2("test2");
Later I need the DOM representaion of the RootElement (to make XML
signatures with Apache xml-security library), but it seems that there is
a problem with the namespaces. In fact if I serialize the RootElement
the namespaces are not included:
System.out.println(redoc.getRootElement().toString());
The output is: <xml-fragment ID="id1000" attr1="test1" attr2="test2"/>
(Notice that there is NO NAMESPACES)
But I parse a valid xml-document:
<app1:RootElement ID="id1000" attr1="test1" attr2="test2"
xmlns:app1="http://www.apache.org/ns/#app1"><ds:Signature
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
<ds:SignatureMethod
Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
<ds:Reference URI="#id1000"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:Transforms xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
<ds:Transform
Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
<ds:DigestValue
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">BO5SsuaM5ySxeHiIAC+uF7zYWw0=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">KKaZvuWdLXOBWMZx6WMt7QfLU79j9YDIYAUY0SXEct7+cHHfBuURHQ==</ds:SignatureValue>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:X509Certificate xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
MIIC9jCCArQCBDruqiowCwYHKoZIzjgEAwUAMGExCzAJBgNVBAYTAkRFMR0wGwYDVQQKExRVbml2
ZXJzaXR5IG9mIFNpZWdlbjEQMA4GA1UECxMHRkIxMk5VRTEhMB8GA1UEAxMYQ2hyaXN0aWFuIEdl
dWVyLVBvbGxtYW5uMB4XDTAxMDUwMTEyMjA1OFoXDTA2MTAyMjEyMjA1OFowYTELMAkGA1UEBhMC
REUxHTAbBgNVBAoTFFVuaXZlcnNpdHkgb2YgU2llZ2VuMRAwDgYDVQQLEwdGQjEyTlVFMSEwHwYD
VQQDExhDaHJpc3RpYW4gR2V1ZXItUG9sbG1hbm4wggG3MIIBLAYHKoZIzjgEATCCAR8CgYEA/X9T
gR11EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv
8mZgt2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HX
Ku/yIgMZndFIAccCFQCXYFCPFSMLzLKSuYKi64QL8Fgc9QKBgQD34aCF1ps93su8q1w2uFe5eZSv
u/o66oL5V0wLPQeCZ1FZV4661FlP5nEHEIGAtEkWcSPoTCgWE7fPCTKMyKbhPBZ6i1R8jSjgo64e
K7OmdZFuo38L+iE1YvH7YnoBJDvMpPG+qFGQiaiD3+Fa5Z8GkotmXoB7VSVkAUw7/s9JKgOBhAAC
gYASWfn+G1k/nWntj9jX7Nk5JKaiLZ9BLR16eJJxqff33THLfdGs98Xmh2oRWZVh9PMV8oTP3hpR
cRipjZUZVEIqsBlOGTVLCg4H5TJ81JWOiprh+mkhClNqUr8l5Hu7FBSvQB6inryeva7j0aKNiIvK
8vfHTiUZpnyNRhkveBlM0jALBgcqhkjOOAQDBQADLwAwLAIUPDd/UmB9GeHqvGjny30Bvjt0AkUC
FA9ab72kKuB5geYGeckbBrcgPnZk
</ds:X509Certificate>
</ds:X509Data>
<ds:KeyValue xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:DSAKeyValue xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:P xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
/X9TgR11EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuA
HTRv8mZgt2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOu
K2HXKu/yIgMZndFIAcc=
</ds:P>
<ds:Q
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">l2BQjxUjC8yykrmCouuEC/BYHPU=</ds:Q>
<ds:G xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
9+GghdabPd7LvKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3
zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/hWuWfBpKL
Zl6Ae1UlZAFMO/7PSSo=
</ds:G>
<ds:Y xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
Eln5/htZP51p7Y/Y1+zZOSSmoi2fQS0deniScan3990xy33RrPfF5odqEVmVYfTzFfKEz94aUXEY
qY2VGVRCKrAZThk1SwoOB+UyfNSVjoqa4fppIQpTalK/JeR7uxQUr0Aeop68nr2u49GijYiLyvL3
x04lGaZ8jUYZL3gZTNI=
</ds:Y>
</ds:DSAKeyValue>
</ds:KeyValue>
</ds:KeyInfo>
</ds:Signature></app1:RootElement>
and I serialize the same RootElement
RootElementDocument redoc =
RootElementDocument.Factory.parse(new File("xml/file.xml"));
System.out.println(redoc.getRootElement().toString());
the out contains the valid namespaces:
<xml-fragment ID="id1000" attr1="test1" attr2="test2"
xmlns:app1="http://www.apache.org/ns/#app1">
To make XML signatures over XML created with XMLBEANS, I am using Apache
xml-security. It needs the DOM API and I obtain the DOM with
getDomNode() method. But when I made the signature the signed info it is
applied over the document but the namespaces are not included but some
strange reason.
Any clue about what it is happening?
Another question? Do you know it is planned to include in XMLBeans a
complete DOM implementation (DomInterface...)
Regards,
Evaristo Camarero
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org