arabica/include/DOM/Simple/Helpers.h

54 lines
2 KiB
C
Raw Normal View History

2002-06-21 13:16:28 +02:00
#ifndef JEZUK_SimpleDOM_HELPERSH
#define JEZUK_SimpleDOM_HELPERSH
#include <DOM/Node.h>
#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)
{
// DOM mandates xmlns: be bound to a namespace URI, XML Namespace rec
// says not - allow for both here
if((namespaceURI == xmlnsURI) || (string_adaptorT::empty(namespaceURI)))
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)
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