I need to add an element to an existing XML document which uses a namespace that doesn't exist in the original. How do I do this?
Ideally I would like to use REXML for portability, but any common XML library would be okay. An ideal solution would be smart about namespace collisions.
I have an xml document which looks like this:
<xrds:XRDS
xmlns:xrds="xri://$xrds"
xmlns="xri://$xrd*($v*2.0)">
<XRD>
<Service>
<Type>http://specs.openid.net/auth/2.0/signon</Type>
<URI>http://provider.openid.example/server/2.0</URI>
</Service>
</XRD>
</xrds:XRDS>
and add:
<Service
xmlns="xri://$xrd*($v*2.0)"
xmlns:openid="http://openid.net/xmlns/1.0">
<Type>http://openid.net/signon/1.0</Type>
<URI>http://provider.openid.example/server/1.0</URI>
<openid:Delegate>http://example.openid.example</openid:Delegate>
</Service>
Yielding something equivalent to:
<xrds:XRDS
xmlns:xrds="xri://$xrds"
xmlns="xri://$xrd*($v*2.0)"
xmlns:openid="http://openid.net/xmlns/1.0">
<XRD>
<Service>
<Type>http://specs.openid.net/auth/2.0/signon</Type>
<URI>http://provider.openid.example/server/2.0</URI>
</Service>
<Service>
<Type>http://openid.net/signon/1.0</Type>
<URI>http://provider.openid.example/server/1.0</URI>
<openid:Delegate>http://example.openid.example</openid:Delegate>
</Service>
</XRD>
</xrds:XRDS>