Mapping XML Namespaces to C++ Namespaces
If the schema contains a namespace declaration that associates a prefix to the target namespace URI, by default this prefix is used as the C++ namespace for the generated classes. In the example schema element declaration below, the po prefix is associated with the URI that matches the value of the targetNamespace attribute, so the classes would be generated within the po namespace.
 
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:po="http://www.example.com/PO1"
targetNamespace="http://www.example.com/PO1"
...
To use the generated classes you must prefix the type with the po namespace or make the name accessible with a using directive or using declaration. The following code snippets show both options.
Prefixing the type with a the po namespace:
 
// Code Example with C++ namespace qualified type name
int main() {
...
po::PurchaseOrderType order;
...
}
Importing all names in po with a using directive:
 
// Code Example with using directive
using namespace po;
 
int main() {
...
PurchaseOrderType order;
...
}
Importing po::PurchaseOrderType with a using declaration:
 
// Code Example with using declaration
using po::PurchaseOrderType;
 
int main() {
...
PurchaseOrderType order;
...
}
Instead of using the XML namespace prefix as the C++ namespace, you can choose your own C++ namespace through the use of the mappings element in a HydraExpress project file. The mapping element shown below instructs the code generator to generate the classes that are defined within the target namespace http://www.example.com/PO1, using the C++ namespace named POTypes.
 
<mappings>
<namespace uri="http://www.example.com/PO1" name="POTypes"/>
</mappings>