Adding a Namespace to a Root Element
You can add a namespace to the root element without adding it to any children elements. To do so, use the addNamespaceDecl() function on rwsf::XmlStringWriter.
For example, the code below adds a namespace to the root element of myDocument:
 
#include <rwsf/core/XmlWriter.h> //1
#include <rwsf/core/XmlName.h>
#include <rwsf/core/XmlStringWriter.h>
#include <rwsf/core/XmlNamespace.h>
 
XmlStringWriter marshalWriter; //2
XmlNamespace qbNamespace("qb", "http://www.roguewave.com/Schema/Project"); //3
marshalWriter.addNamespaceDecl(qbNamespace); //4
myDocument.marshal( marshalWriter); //5
std::cout << "Marshal: " << marshalWriter.getString() << std::endl; //6
 
//1 Necessary includes.
//2 Creates a writer to marshal your object.
//3 Set the namespace with “qb” as the prefix and http://www.roguewave.com/Schema/Project as the URI.
//4 Invokes addNamespaceDecl() with the provided namespace.
//5 Marshals the object.
//6 Prints to standard out the marshaled XML document.
Once marshaled, the XML document contains the root namespace:
 
<?xml version="1.0" encoding="utf-8"?>
<my Document xmlns="http://www.roguewave.com/XMLSchema"
xmlns:qb="http://www.roguewave.com/Schema/Project">
...
</myDocument>