This Version: August 6, 2001
Latest Version: http://simonstl.com/ns/namespaces/elements/replace/
Previous Version: None
Editors:
This vocabulary is used by a filter, com.simonstl.namespace.elements.ElementReplNamespaceFilter
, which simply replaces namespaces used by elements in the document. 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 elements 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"> <givenName>Chip</givenName> <familyName>Skillet</familyName> <address> <z:street xmlns:z="http://simonstl.com/address">1259 Zingzang Road</z:street> <city>Ithaca</city> </address> </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/elements/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.elements.ElementReplFilterTester replaceEl1.xml test2.xml <?xml version="1.0" standalone="yes"?> <p:person xmlns:p="http://example.com/"> <givenName>Chip</givenName> <familyName>Skillet</familyName> <address> <z:street xmlns:z="http://simonstl.com/address">1259 Zingzang Road</z:street> <city>Ithaca</city> </address> </p:person>
The http://simonstl.com/address
namespace remains unchanged, while http://simonstl.com/person
becomes http://example.com/
.
The next set of rules also changes the prefix:
<namespaces xmlns="http://simonstl.com/ns/namespaces/elements/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.elements.ElementReplFilterTester replaceEl2.xml test2.xml <?xml version="1.0" standalone="yes"?> <example:person xmlns:example="http://example.com/"> <givenName>Chip</givenName> <familyName>Skillet</familyName> <address> <z:street xmlns:z="http://simonstl.com/address">1259 Zingzang Road</z:street> <city>Ithaca</city> </address> </example: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 remove a prefix:
<namespaces xmlns="http://simonstl.com/ns/namespaces/elements/replace/"> <replace matchURI="http://simonstl.com/person" resultURI="http://example.com/1" resultPrefix="example"/> <replace matchURI="http://simonstl.com/address" 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.elements.ElementReplFilterTester replaceEl3.xml test2.xml <?xml version="1.0" standalone="yes"?> <example:person xmlns:example="http://example.com/1"> <givenName>Chip</givenName> <familyName>Skillet</familyName> <address> <street xmlns="http://example.com/2">1259 Zingzang Road</street> <city>Ithaca</city> </address> </example:person>
The http://simonstl.com/address
namespace becomes http://example.com/2
, and the z
prefix is removed entirely. The http://simonstl.com/person
becomes http://example.com/1
. Again, the prefix p
became example
.