When generating some assertions the spaces at the end of a String are
removed and we need then there. The interesting part of the xml schema,
we are using to encode the assertions looks like this, changing the
schema is not an option.
<complexType name="GeneralDateType">
<sequence>
<element name="DateString">
<simpleType>
<restriction base="string">
<pattern value="[0-9 ]{8}" />
<whiteSpace value="preserve" />
</restriction>
</simpleType>
</element>
<element name="DateValue" type="date" minOccurs="0" />
</sequence>
</complexType>
A value like this: "200103 " is allowed and we have to set it with
spaces at the end.
Our current code for generating this DateString element looks like this:
XSAny child = new XSAnyBuilder().buildObject(new
QName("http://mydomain.de/namespace123/", "DateString", "ipd"));
child.setTextContent("200103 ");
How do we set the <whiteSpace value="preserve" /> in XMLTooling? With
this code OpenSAML or XMLTooling removes the spaces at the end like the
XML spec says for normal XML Strings without any special whiteSpace element.
The resulting XML looks like this:
<saml2:AttributeValue
xmlns=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:idp=\"http://mydomain.de/namespace123/\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:type=\"idp:GeneralDateType\"><idp:DateString>200103</idp:DateString></saml2:AttributeValue>
We want the xml to look like this:
<idp:DateString>200103 </idp:DateString>
How do we generate such an xml with OpenSAML and XMLTooling?
Hauke Mehrtens
On 3/21/11 11:33 AM, Hauke Mehrtens wrote:
> The resulting XML looks like this:
>
> <saml2:AttributeValue
> xmlns=\"http://www.w3.org/2001/XMLSchema-instance\"
> xmlns:idp=\"http://mydomain.de/namespace123/\"
> xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
> xsi:type=\"idp:GeneralDateType\"><idp:DateString>200103</idp:DateString></saml2:AttributeValue>
>
> We want the xml to look like this:
> <idp:DateString>200103 </idp:DateString>
>
> How do we generate such an xml with OpenSAML and XMLTooling?
We don't have any built-in options for preserving space like that. That
only way that you can achieve is custom XMLObject provider classes. The
relevant method that you would need to customized/override is in the
AbstractXMLObject:
protected String prepareForAssignment(String oldValue, String newValue)
{ ...}
That is where the whitespace trimming is happening.
Since you have a non-trivial complex type, I'd recommend that, instead
of using the XSAny default provider, you create an XMLObject interface
and impl, marshaller, and unmarshaller for your complex type, and then
register that provider set in the configuration for the type
idp:GeneralDateType. That would be the complete and "proper" way to do
this.
A quick and dirty way, using the XSAny approach, would be to just
subclass XSAnyImpl, override prepareForAssignment, and then create a
builder that uses that new subclass rather than the default XSAnyImpl.
Hope that helps,
Brent
On 3/21/11 12:09 PM, Brent Putman wrote:
>
> Since you have a non-trivial complex type, I'd recommend that, instead
> of using the XSAny default provider, you create an XMLObject interface
> and impl, marshaller, and unmarshaller for your complex type, and then
> register that provider set in the configuration for the type
> idp:GeneralDateType. That would be the complete and "proper" way to do
> this.
I meant to add that some documentation for how to do this can be found
in the developer's manual:
https://spaces.internet2.edu/display/OpenSAML/OSTwoDeveloperManual