2002-06-21 13:16:28 +02:00
|
|
|
#ifndef JEZUK_SimpleDOM_HELPERSH
|
|
|
|
#define JEZUK_SimpleDOM_HELPERSH
|
|
|
|
|
2007-09-05 00:55:47 +02:00
|
|
|
#include <DOM/Node.hpp>
|
2002-06-21 13:16:28 +02:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace SimpleDOM
|
|
|
|
{
|
|
|
|
|
|
|
|
template<class stringT, class string_adaptorT>
|
|
|
|
std::pair<bool, stringT> checkPrefixAndNamespace(bool hasPrefix,
|
|
|
|
const stringT& prefix,
|
|
|
|
bool hasNamespaceURI,
|
|
|
|
const stringT& namespaceURI,
|
2002-11-23 21:03:54 +01:00
|
|
|
typename DOM::Node<stringT>::Type nodeType)
|
2002-06-21 13:16:28 +02:00
|
|
|
{
|
2005-09-30 23:36:11 +02:00
|
|
|
const stringT xml = string_adaptorT::construct_from_utf8("xml");
|
|
|
|
const stringT xmlURI = string_adaptorT::construct_from_utf8("http://www.w3.org/XML/1998/namespace");
|
|
|
|
const stringT xmlns = string_adaptorT::construct_from_utf8("xmlns");
|
|
|
|
const stringT xmlnsURI = string_adaptorT::construct_from_utf8("http://www.w3.org/2000/xmlns/");
|
2002-06-21 13:16:28 +02:00
|
|
|
|
|
|
|
if(!hasPrefix)
|
|
|
|
return std::make_pair(hasNamespaceURI, namespaceURI);
|
|
|
|
|
2006-06-08 11:51:18 +02:00
|
|
|
if(string_adaptorT::find(prefix, string_adaptorT::construct_from_utf8(":")) != string_adaptorT::npos())
|
2002-06-21 13:16:28 +02:00
|
|
|
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
|
|
|
|
|
|
|
if(prefix == xml)
|
|
|
|
{
|
|
|
|
if(namespaceURI == xmlURI)
|
|
|
|
return std::make_pair(true, namespaceURI);
|
|
|
|
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
|
|
|
} // if(prefix == xml)
|
|
|
|
|
|
|
|
if(nodeType == DOM::Node<stringT>::ATTRIBUTE_NODE && prefix == xmlns)
|
|
|
|
{
|
2003-12-07 16:23:55 +01:00
|
|
|
// DOM mandates xmlns: be bound to a namespace URI, XML Namespace rec
|
|
|
|
// says not - allow for both here
|
2005-09-08 23:43:21 +02:00
|
|
|
if((namespaceURI == xmlnsURI) || (string_adaptorT::empty(namespaceURI)))
|
2003-12-07 16:23:55 +01:00
|
|
|
return std::make_pair(true, xmlnsURI);
|
2002-06-21 13:16:28 +02:00
|
|
|
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
|
|
|
} // if(nodeType == DOM::Node<stringT>::ATTRIBUTE_NODE && prefix == xmlns)
|
|
|
|
|
2005-09-08 23:43:21 +02:00
|
|
|
if(hasNamespaceURI == false || string_adaptorT::empty(namespaceURI))
|
2002-06-21 13:16:28 +02:00
|
|
|
throw DOM::DOMException(DOM::DOMException::NAMESPACE_ERR);
|
|
|
|
|
|
|
|
return std::make_pair(true, namespaceURI);
|
|
|
|
} // checkPrefixAndNamespace
|
|
|
|
|
|
|
|
} // namespace SimpleDOM
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|