Provide a unique integer ID for each XML namespace.
More...
Detailed Description
- Outline
-
-
- Purpose:
- Provide a unique integer ID for each XML namespace.
-
- Classes:
-
- See also:
- Component balxml_namespaceregistry
-
- Description:
balxml::PrefixStack
keeps a collection of pairs - the prefix string and the integer associated with each namespace uri. Registration of prefix with namespace works similar to "pushing in stack", i.e., it hides the previous prefix<->namespaces association. Deregistration of prefix removes the current association and opens the previous association of given prefix.
- It is safe to read or modify multiple instances of
balxml::PrefixStack
simultaneously, each from a separate thread. It is safe to read a single instance of balxml::PrefixStack
from multiple threads, provided no thread is modifying it at the same time. It is not safe to read or modify an instance of balxml::PrefixStack
from one thread while any other thread is modifying the same instance. Modifying a balxml::PrefixStack
objects may modify the referenced balxml::NamespaceRegistry
object. It is not safe to read or modify an instance of balxml::PrefixStack
from one thread while any other thread is (directly or indirectly) modifying the referenced balxml::NamespaceRegistry
.
-
- Usage:
- In this example we demonstrate registering several prefixes with different namespaces and printing them along with their ID.
balxml::NamespaceRegistry namespaces;
balxml::PrefixStack prefixes(namespaces, allocator);
bsl::string uri1 = "http://www.google.com";
bsl::string uri2 = "http://www.yahoo.com";
bsl::string uri3 = "http://www.hotmail.com";
bsl::string uri4 = "http://www.msn.com";
bsl::string prefix1 = "a";
bsl::string prefix2 = "b";
bsl::string prefix3 = "c";
int namespaceId1 = prefixes.pushPrefix(prefix1, uri1);
int namespaceId2 = prefixes.pushPrefix(prefix2, uri2);
int namespaceId3 = prefixes.pushPrefix(prefix3, uri3);
bsl::cout << prefix1 << ":" << namespaceId1 << bsl::endl;
bsl::cout << prefix2 << ":" << namespaceId2 << bsl::endl;
bsl::cout << prefix3 << ":" << namespaceId3 << bsl::endl;
int namespaceId4 = prefixes.pushPrefix(prefix1, uri4);
bsl::cout << prefix1 << ":" << namespaceId1 << bsl::endl;
prefixes.popPrefix(prefix1);
bsl::cout << prefix1 << ":" << namespaceId1 << bsl::endl;