27#include <com/sun/star/uno/Reference.hxx>
28#include <com/sun/star/xml/dom/XAttr.hpp>
29#include <com/sun/star/xml/dom/XNode.hpp>
30#include <com/sun/star/xml/dom/XElement.hpp>
31#include <com/sun/star/xml/dom/NodeType.hpp>
32#include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
34#include <rtl/ustring.hxx>
35#include <rtl/ustrbuf.hxx>
37#include <osl/diagnose.h>
44using com::sun::star::uno::UNO_QUERY_THROW;
55 virtual ~DomVisitor() {}
69 switch( xNode->getNodeType() )
71 case NodeType_ATTRIBUTE_NODE:
73 case NodeType_CDATA_SECTION_NODE:
75 case NodeType_COMMENT_NODE:
77 case NodeType_DOCUMENT_FRAGMENT_NODE:
79 case NodeType_DOCUMENT_NODE:
81 case NodeType_DOCUMENT_TYPE_NODE:
83 case NodeType_ELEMENT_NODE:
86 case NodeType_ENTITY_NODE:
88 case NodeType_ENTITY_REFERENCE_NODE:
90 case NodeType_NOTATION_NODE:
92 case NodeType_PROCESSING_INSTRUCTION_NODE:
94 case NodeType_TEXT_NODE:
98 OSL_FAIL(
"unknown DOM node type" );
113 xChild = xChild->getNextSibling() )
115 visit( rVisitor, xChild );
117 if( xNode->getNodeType() == NodeType_ELEMENT_NODE )
123class DomExport:
public DomVisitor
126 vector<SvXMLNamespaceMap> maNamespaces;
128 void pushNamespace();
129 void addNamespace(
const OUString&
sPrefix,
const OUString& sURI );
130 OUString qualifiedName(
const OUString&
sPrefix,
const OUString& sURI,
131 const OUString& sLocalName );
139 virtual ~DomExport()
override;
154DomExport::~DomExport()
156 SAL_WARN_IF( maNamespaces.size() != 1,
"xmloff",
"namespace missing" );
157 maNamespaces.clear();
160void DomExport::pushNamespace()
163 maNamespaces.push_back(aMap);
166void DomExport::addNamespace(
const OUString&
sPrefix,
const OUString& sURI )
178 mrExport.AddAttribute(
"xmlns:" +
sPrefix, sURI );
182OUString DomExport::qualifiedName(
const OUString&
sPrefix,
183 const OUString& sURI,
184 const OUString& sLocalName )
186 if( !
sPrefix.isEmpty() && !sURI.isEmpty() )
189 return sPrefix +
":" + sLocalName;
197 return qualifiedName( xElement->getPrefix(), xElement->getNamespaceURI(),
198 xElement->getNodeName() );
203 return qualifiedName( xAttr->getPrefix(), xAttr->getNamespaceURI(),
204 xAttr->getNodeName() );
209 mrExport.AddAttribute( qualifiedName( xAttribute ),
210 xAttribute->getNodeValue() );
219 sal_Int32
nLength = xAttributes.is() ? xAttributes->getLength() : 0;
222 addAttribute(
Reference<XAttr>( xAttributes->item( n ), UNO_QUERY_THROW ) );
226 mrExport.StartElement( qualifiedName( xElement ),
false );
231 mrExport.EndElement( qualifiedName( xElement ),
false );
232 maNamespaces.pop_back();
237 mrExport.Characters( xChars->getNodeValue() );
243 DomExport aDomExport( rExport );
244 visit( aDomExport, xDocument );
void exportDom(SvXMLExport &rExport, const Reference< XDocument > &xDocument)
static void visit(DomVisitor &, const Reference< XDocument > &)
static void visitNode(DomVisitor &rVisitor, const Reference< XNode > &xNode)
const SvXMLNamespaceMap & GetNamespaceMap() const
const OUString & GetNameByKey(sal_uInt16 nKey) const
sal_uInt16 GetKeyByPrefix(const OUString &rPrefix) const
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
#define SAL_WARN_IF(condition, area, stream)
const sal_uInt16 XML_NAMESPACE_UNKNOWN
HashMap_OWString_Interface aMap