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
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>