This Version: August 6, 2001
Latest Version: http://simonstl.com/ns/namespaces/attributes/replace/
Previous Version: None
Editors:
This vocabulary is used by com.simonstl.namespace.attributes.AttribReplNamespaceFilter
to define which namespaces on attributes should be replaced by other namespaces. The vocabulary provides a list of namespaces which should be replaced by other specified namespaces, optionally set with a particular prefix.
Warning: use of this technique may change the meaning of your documents substantially. Use it with care after studying options and impact.
The rules for replacing namespaces on attributes work quite simply. Namespaces in the original document (identified by matchURI
) are mapped to namespaces in the result (resultURI
). If desired, a prefix (resultPrefix
) may be specified for the result namespace.
The example rule sets will be applied to this document:
<p:person xmlns:p="http://simonstl.com/person" xmlns:z="http://simonstl.com/nothing" > <z:name p:givenName="Chip" p:familyName="Skillet" /> <z:address p:city="Ithaca" z:planet="earth" /> </p:person>
The first rule we'll examine changes the http://simonstl.com/person
namespace to http://example.com/
, but makes no other changes:
<namespaces xmlns="http://simonstl.com/ns/namespaces/attributes/replace/"> <replace matchURI="http://simonstl.com/person" resultURI="http://example.com/" /> </namespaces>
When applied to the document, we get:
C:\opensrc\namespace>java com.simonstl.namespace.attributes.AttribReplFilterTester replaceAtt1.xml atttest2.xml <?xml version="1.0" standalone="yes"?> <p:person xmlns:p="http://simonstl.com/person"> <z:name __NS1:givenName="Chip" __NS1:familyName="Skillet" xmlns:z="http://simonstl.com/nothing" xmlns:__NS1="http://example.com/"></z:name> <z:address __NS1:city="Ithaca" z:planet="earth" xmlns:z="http://simonstl.com/nothing" xmlns:__NS1="http://example.com/"></z:address> </p:person>
The http://simonstl.com/address
namespace remains unchanged, while http://simonstl.com/person
becomes http://example.com/
. The XMLWriter
creates its own namespace prefix for the new namespace URI.
The next set of rules also changes the prefix:
<namespaces xmlns="http://simonstl.com/ns/namespaces/attributes/replace/"> <replace matchURI="http://simonstl.com/person" resultURI="http://example.com/" resultPrefix="example"/> </namespaces>
When applied to the document, the namespace URI and the prefix both change:
C:\opensrc\namespace>java com.simonstl.namespace.attributes.AttribReplFilterTester replaceAtt2.xml atttest2.xml <?xml version="1.0" standalone="yes"?> <p:person xmlns:p="http://simonstl.com/person"> <z:name example:givenName="Chip" example:familyName="Skillet" xmlns:z="http://simonstl.com/nothing" xmlns:example="http://example.com/"></z:name> <z:address example:city="Ithaca" z:planet="earth" xmlns:z="http://simonstl.com/nothing" xmlns:example="http://example.com/"></z:address> </p:person>
Once again, the http://simonstl.com/address
namespace remains unchanged, while http://simonstl.com/person
becomes http://example.com/
. This time, however, the prefix p
became example
.
The last example demonstrates how to replace multiple namespaces simultaneously, and (well, not quite) remove a prefix:
<namespaces xmlns="http://simonstl.com/ns/namespaces/attributes/replace/"> <replace matchURI="http://simonstl.com/person" resultURI="http://example.com/1" resultPrefix="example"/> <replace matchURI="http://simonstl.com/nothing" resultURI="http://example.com/2" resultPrefix=""/> </namespaces>
This rule has a more dramatic effect on the contents of the document:
C:\opensrc\namespace>java com.simonstl.namespace.attributes.AttribReplFilterTester replaceAtt3.xml atttest2.xml <?xml version="1.0" standalone="yes"?> <p:person xmlns:p="http://simonstl.com/person"> <z:name example:givenName="Chip" example:familyName="Skillet" xmlns:z="http://simonstl.com/nothing" xmlns:example="http://example.com/1"></z:name> <z:address example:city="Ithaca" __NS1:planet="earth" xmlns:z="http://simonstl.com/nothing" xmlns:example="http://example.com/1" xmlns:__NS1="http://example.com /2"></z:address> </p:person>
The http://simonstl.com/address
namespace becomes http://example.com/2
, and the z
prefix is removed entirely - except that the XMLWriter
used for output insists on applying its own prefix to namespace-qualified attributes. The http://simonstl.com/person
becomes http://example.com/1
. Again, the prefix p
became example
.