This Version: August 6, 2001
Latest Version: http://simonstl.com/ns/namespaces/elements/annotate/
Previous Version: None
Editors:
This vocabulary is used by a filter, com.simonstl.namespace.elements.ElementAnnotNamespaceFilter
, which annotates unqualified descendant elements of qualified elements with information about their ancestor's namespace. It is a less intrusive approach than the forced-qualification approach. It is also more easily reversed or ignored if necessary.
Warning: use of this technique modifies the content of documents. Use it with care after studying options and impact.
The rules vocabulary for annotation works exactly like the rules vocabulary for forced-qualification, except that the namespace is different (http://simonstl.com/ns/namespace/elements/annotate/
instead of http://simonstl.com/ns/namespace/elements/
) and the results are less dramatic. Unqualified child elements get an extra attribute, not a change in namespace.
The examples use the ElementAnnotFilterTester
class, which takes a rules file and a target file as arguments and returns results to standard output. All of the examples apply rules 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>
For our first example, we'll create a rules file which specifies annotation for only the http://simonstl.com/person
namespace:
<namespaces xmlns="http://simonstl.com/ns/namespaces/elements/annotate/"> <include nsURI="http://simonstl.com/person" /> </namespaces>
Applying this rule produces:
C:\opensrc\namespace>java com.simonstl.namespace.elements.ElementAnnotFilterTester annotEl1.xml test2.xml <?xml version="1.0" standalone="yes"?> <p:person xmlns:p="http://simonstl.com/person"> <givenName an:lastNSContext="http://simonstl.com/person" xmlns:an="http://simonstl.com/ns/namespaces/elements/lastContext/">Chip</givenName> <familyName an:lastNSContext="http://simonstl.com/person" xmlns:an="http://simonstl.com/ns/namespaces/elements/lastContext/">Skillet</familyName> <address an:lastNSContext="http://simonstl.com/person" xmlns:an="http://simonstl.com/ns/namespaces/elements/lastContext/"> <z:street xmlns:z="http://simonstl.com/address">1259 Zingzang Road</z:street> <city an:lastNSContext="http://simonstl.com/person">Ithaca</city> </address> </p:person>
The next rules file uses ##any
to apply this processing to all namespaces:
<namespaces xmlns="http://simonstl.com/ns/namespaces/elements/annotate/"> <include nsURI="##any" /> </namespaces>
This produces:
C:\opensrc\namespace>java com.simonstl.namespace.elements.ElementAnnotFilterTester annotEl2.xml test2.xml <?xml version="1.0" standalone="yes"?> <p:person xmlns:p="http://simonstl.com/person"> <givenName an:lastNSContext="http://simonstl.com/person" xmlns:an="http://simonstl.com/ns/namespaces/elements/lastContext/">Chip</givenName> <familyName an:lastNSContext="http://simonstl.com/person" xmlns:an="http://simonstl.com/ns/namespaces/elements/lastContext/">Skillet</familyName> <address an:lastNSContext="http://simonstl.com/person" xmlns:an="http://simonstl.com/ns/namespaces/elements/lastContext/"> <z:street xmlns:z="http://simonstl.com/address">1259 Zingzang Road</z:street> <city an:lastNSContext="http://simonstl.com/person">Ithaca</city> </address> </p:person>
The next two rules demonstrate exclusions. First, a simple one that sets up an inclusion and an exclusion for the http://simonstl.com/person
namespace:
<namespaces xmlns="http://simonstl.com/ns/namespaces/elements/annotate/"> <include nsURI="http://simonstl.com/person" /> <exclude nsURI="http://simonstl.com/person"/> </namespaces>
This produces:
C:\opensrc\namespace>java com.simonstl.namespace.elements.ElementAnnotFilterTester annotEl3.xml test2.xml <?xml version="1.0" standalone="yes"?> <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>
Finally, we'll include ##any
but exclude the http://simonstl.com/person
namespace.
<namespaces xmlns="http://simonstl.com/ns/namespaces/elements/annotate/"> <include nsURI="##any" /> <exclude nsURI="http://simonstl.com/person"/> </namespaces>
This produces:
C:\opensrc\namespace>java com.simonstl.namespace.elements.ElementAnnotFilterTester annotEl4.xml test2.xml <?xml version="1.0" standalone="yes"?> <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>
Again, the unqualified namespaces for http://simonstl.com/person
are not modified.