/*
- * Copyright 2001-2007 Internet2
+ * Copyright 2001-2009 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "internal.h"
#include "exceptions.h"
+#include "QName.h"
+#include "XMLObject.h"
#include "util/XMLHelper.h"
#include "util/XMLConstants.h"
bool XMLHelper::hasXSIType(const DOMElement* e)
{
- if (e) {
- if (e->hasAttributeNS(xmlconstants::XSI_NS, type)) {
- return true;
- }
- }
-
- return false;
+ return (e && e->hasAttributeNS(xmlconstants::XSI_NS, type));
}
xmltooling::QName* XMLHelper::getXSIType(const DOMElement* e)
return NULL;
}
+void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, set<xstring>& prefixes)
+{
+ set<xstring> child_prefixes;
+ const list<XMLObject*>& children = tree.getOrderedChildren();
+ for (list<XMLObject*>::const_iterator i = children.begin(); i != children.end(); ++i) {
+ if (*i)
+ getNonVisiblyUsedPrefixes(*(*i), child_prefixes);
+ }
+ const set<Namespace>& nsset = tree.getNamespaces();
+ for (set<Namespace>::const_iterator ns = nsset.begin(); ns != nsset.end(); ++ns) {
+ // Check for xmlns:xml.
+ if (XMLString::equals(ns->getNamespacePrefix(), xmlconstants::XML_PREFIX) && XMLString::equals(ns->getNamespaceURI(), xmlconstants::XML_NS))
+ continue;
+ switch (ns->usage()) {
+ case Namespace::Indeterminate:
+ break;
+ case Namespace::VisiblyUsed:
+ child_prefixes.erase(ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull);
+ break;
+ case Namespace::NonVisiblyUsed:
+ prefixes.insert(ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull);
+ break;
+ }
+ }
+ prefixes.insert(child_prefixes.begin(), child_prefixes.end());
+}
+
xmltooling::QName* XMLHelper::getNodeQName(const DOMNode* domNode)
{
if (domNode)
return childElement;
}
+bool XMLHelper::isNodeNamed(const xercesc::DOMNode* n, const XMLCh* ns, const XMLCh* local)
+{
+ return (n && XMLString::equals(local,n->getLocalName()) && XMLString::equals(ns,n->getNamespaceURI()));
+}
+
const XMLCh* XMLHelper::getTextContent(const DOMElement* e)
{
DOMNode* child=e->getFirstChild();
XercesJanitor<DOMLSSerializer> janitor(serializer);
if (pretty && serializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, pretty))
serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, pretty);
- DOMLSOutput *theOutput = static_cast<DOMImplementationLS*>(impl)->createLSOutput();\r
- XercesJanitor<DOMLSOutput> j_theOutput(theOutput);\r
- theOutput->setEncoding(UTF8);\r
+ DOMLSOutput *theOutput = static_cast<DOMImplementationLS*>(impl)->createLSOutput();
+ XercesJanitor<DOMLSOutput> j_theOutput(theOutput);
+ theOutput->setEncoding(UTF8);
theOutput->setByteStream(&target);
if (!serializer->write(n, theOutput))
throw XMLParserException("unable to serialize XML");
XercesJanitor<DOMLSSerializer> janitor(serializer);
if (pretty && serializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, pretty))
serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, pretty);
- DOMLSOutput *theOutput = static_cast<DOMImplementationLS*>(impl)->createLSOutput();\r
- XercesJanitor<DOMLSOutput> j_theOutput(theOutput);\r
- theOutput->setEncoding(UTF8);\r
+ DOMLSOutput *theOutput = static_cast<DOMImplementationLS*>(impl)->createLSOutput();
+ XercesJanitor<DOMLSOutput> j_theOutput(theOutput);
+ theOutput->setEncoding(UTF8);
theOutput->setByteStream(&target);
if (!serializer->write(n, theOutput))
throw XMLParserException("unable to serialize XML");