mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-21 23:56:54 +02:00
XML: complete merge from 1.4.2
This commit is contained in:
@@ -36,7 +36,12 @@
|
||||
|
||||
#include "Poco/DOM/AbstractContainerNode.h"
|
||||
#include "Poco/DOM/Document.h"
|
||||
#include "Poco/DOM/Element.h"
|
||||
#include "Poco/DOM/Attr.h"
|
||||
#include "Poco/DOM/DOMException.h"
|
||||
#include "Poco/DOM/ElementsByTagNameList.h"
|
||||
#include "Poco/DOM/AutoPtr.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -322,4 +327,245 @@ bool AbstractContainerNode::hasAttributes() const
|
||||
}
|
||||
|
||||
|
||||
Node* AbstractContainerNode::getNodeByPath(const XMLString& path) const
|
||||
{
|
||||
XMLString::const_iterator it = path.begin();
|
||||
if (it != path.end() && *it == '/')
|
||||
{
|
||||
++it;
|
||||
if (it != path.end() && *it == '/')
|
||||
{
|
||||
++it;
|
||||
XMLString name;
|
||||
while (it != path.end() && *it != '/' && *it != '@' && *it != '[') name += *it++;
|
||||
if (it != path.end() && *it == '/') ++it;
|
||||
if (name.empty()) name += '*';
|
||||
AutoPtr<ElementsByTagNameList> pList = new ElementsByTagNameList(this, name);
|
||||
unsigned long length = pList->length();
|
||||
for (unsigned long i = 0; i < length; i++)
|
||||
{
|
||||
XMLString::const_iterator beg = it;
|
||||
const Node* pNode = findNode(beg, path.end(), pList->item(i), 0);
|
||||
if (pNode) return const_cast<Node*>(pNode);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return const_cast<Node*>(findNode(it, path.end(), this, 0));
|
||||
}
|
||||
|
||||
|
||||
Node* AbstractContainerNode::getNodeByPathNS(const XMLString& path, const NSMap& nsMap) const
|
||||
{
|
||||
XMLString::const_iterator it = path.begin();
|
||||
if (it != path.end() && *it == '/')
|
||||
{
|
||||
++it;
|
||||
if (it != path.end() && *it == '/')
|
||||
{
|
||||
++it;
|
||||
XMLString name;
|
||||
while (it != path.end() && *it != '/' && *it != '@' && *it != '[') name += *it++;
|
||||
if (it != path.end() && *it == '/') ++it;
|
||||
XMLString namespaceURI;
|
||||
XMLString localName;
|
||||
bool nameOK = true;
|
||||
if (name.empty())
|
||||
{
|
||||
namespaceURI += '*';
|
||||
localName += '*';
|
||||
}
|
||||
else
|
||||
{
|
||||
nameOK = nsMap.processName(name, namespaceURI, localName, false);
|
||||
}
|
||||
if (nameOK)
|
||||
{
|
||||
AutoPtr<ElementsByTagNameListNS> pList = new ElementsByTagNameListNS(this, namespaceURI, localName);
|
||||
unsigned long length = pList->length();
|
||||
for (unsigned long i = 0; i < length; i++)
|
||||
{
|
||||
XMLString::const_iterator beg = it;
|
||||
const Node* pNode = findNode(beg, path.end(), pList->item(i), &nsMap);
|
||||
if (pNode) return const_cast<Node*>(pNode);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return const_cast<Node*>(findNode(it, path.end(), this, &nsMap));
|
||||
}
|
||||
|
||||
|
||||
const Node* AbstractContainerNode::findNode(XMLString::const_iterator& it, const XMLString::const_iterator& end, const Node* pNode, const NSMap* pNSMap)
|
||||
{
|
||||
if (pNode && it != end)
|
||||
{
|
||||
if (*it == '[')
|
||||
{
|
||||
++it;
|
||||
if (it != end && *it == '@')
|
||||
{
|
||||
++it;
|
||||
XMLString attr;
|
||||
while (it != end && *it != ']' && *it != '=') attr += *it++;
|
||||
if (it != end && *it == '=')
|
||||
{
|
||||
++it;
|
||||
XMLString value;
|
||||
if (it != end && *it == '\'')
|
||||
{
|
||||
++it;
|
||||
while (it != end && *it != '\'') value += *it++;
|
||||
if (it != end) ++it;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (it != end && *it != ']') value += *it++;
|
||||
}
|
||||
if (it != end) ++it;
|
||||
return findNode(it, end, findElement(attr, value, pNode, pNSMap), pNSMap);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (it != end) ++it;
|
||||
return findAttribute(attr, pNode, pNSMap);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
XMLString index;
|
||||
while (it != end && *it != ']') index += *it++;
|
||||
if (it != end) ++it;
|
||||
return findNode(it, end, findElement(Poco::NumberParser::parse(index), pNode, pNSMap), pNSMap);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (it != end && *it == '/') ++it;
|
||||
XMLString key;
|
||||
while (it != end && *it != '/' && *it != '[') key += *it++;
|
||||
return findNode(it, end, findElement(key, pNode, pNSMap), pNSMap);
|
||||
}
|
||||
}
|
||||
else return pNode;
|
||||
}
|
||||
|
||||
|
||||
const Node* AbstractContainerNode::findElement(const XMLString& name, const Node* pNode, const NSMap* pNSMap)
|
||||
{
|
||||
Node* pChild = pNode->firstChild();
|
||||
while (pChild)
|
||||
{
|
||||
if (pChild->nodeType() == Node::ELEMENT_NODE && namesAreEqual(pChild, name, pNSMap))
|
||||
return pChild;
|
||||
pChild = pChild->nextSibling();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const Node* AbstractContainerNode::findElement(int index, const Node* pNode, const NSMap* pNSMap)
|
||||
{
|
||||
const Node* pRefNode = pNode;
|
||||
if (index > 0)
|
||||
{
|
||||
pNode = pNode->nextSibling();
|
||||
while (pNode)
|
||||
{
|
||||
if (namesAreEqual(pNode, pRefNode, pNSMap))
|
||||
{
|
||||
if (--index == 0) break;
|
||||
}
|
||||
pNode = pNode->nextSibling();
|
||||
}
|
||||
}
|
||||
return pNode;
|
||||
}
|
||||
|
||||
|
||||
const Node* AbstractContainerNode::findElement(const XMLString& attr, const XMLString& value, const Node* pNode, const NSMap* pNSMap)
|
||||
{
|
||||
const Node* pRefNode = pNode;
|
||||
const Element* pElem = dynamic_cast<const Element*>(pNode);
|
||||
if (!(pElem && pElem->hasAttributeValue(attr, value, pNSMap)))
|
||||
{
|
||||
pNode = pNode->nextSibling();
|
||||
while (pNode)
|
||||
{
|
||||
if (namesAreEqual(pNode, pRefNode, pNSMap))
|
||||
{
|
||||
pElem = dynamic_cast<const Element*>(pNode);
|
||||
if (pElem && pElem->hasAttributeValue(attr, value, pNSMap)) break;
|
||||
}
|
||||
pNode = pNode->nextSibling();
|
||||
}
|
||||
}
|
||||
return pNode;
|
||||
}
|
||||
|
||||
|
||||
const Attr* AbstractContainerNode::findAttribute(const XMLString& name, const Node* pNode, const NSMap* pNSMap)
|
||||
{
|
||||
const Attr* pResult(0);
|
||||
const Element* pElem = dynamic_cast<const Element*>(pNode);
|
||||
if (pElem)
|
||||
{
|
||||
if (pNSMap)
|
||||
{
|
||||
XMLString namespaceURI;
|
||||
XMLString localName;
|
||||
if (pNSMap->processName(name, namespaceURI, localName, true))
|
||||
{
|
||||
pResult = pElem->getAttributeNodeNS(namespaceURI, localName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pResult = pElem->getAttributeNode(name);
|
||||
}
|
||||
}
|
||||
return pResult;
|
||||
}
|
||||
|
||||
|
||||
bool AbstractContainerNode::hasAttributeValue(const XMLString& name, const XMLString& value, const NSMap* pNSMap) const
|
||||
{
|
||||
const Attr* pAttr = findAttribute(name, this, pNSMap);
|
||||
return pAttr && pAttr->getValue() == value;
|
||||
}
|
||||
|
||||
|
||||
bool AbstractContainerNode::namesAreEqual(const Node* pNode1, const Node* pNode2, const NSMap* pNSMap)
|
||||
{
|
||||
if (pNSMap)
|
||||
{
|
||||
return pNode1->localName() == pNode2->localName() && pNode1->namespaceURI() == pNode2->namespaceURI();
|
||||
}
|
||||
else
|
||||
{
|
||||
return pNode1->nodeName() == pNode2->nodeName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool AbstractContainerNode::namesAreEqual(const Node* pNode, const XMLString& name, const NSMap* pNSMap)
|
||||
{
|
||||
if (pNSMap)
|
||||
{
|
||||
XMLString namespaceURI;
|
||||
XMLString localName;
|
||||
if (pNSMap->processName(name, namespaceURI, localName, false))
|
||||
{
|
||||
return pNode->namespaceURI() == namespaceURI && pNode->localName() == localName;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return pNode->nodeName() == name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::XML
|
||||
|
||||
@@ -237,9 +237,21 @@ XMLString AbstractNode::innerText() const
|
||||
}
|
||||
|
||||
|
||||
Node* AbstractNode::getNodeByPath(const XMLString& path) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Node* AbstractNode::getNodeByPathNS(const XMLString& path, const NSMap& nsMap) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void AbstractNode::addEventListener(const XMLString& type, EventListener* listener, bool useCapture)
|
||||
{
|
||||
if (_pEventDispatcher)
|
||||
if (_pEventDispatcher)
|
||||
_pEventDispatcher->removeEventListener(type, listener, useCapture);
|
||||
else
|
||||
_pEventDispatcher = new EventDispatcher;
|
||||
|
||||
@@ -106,9 +106,9 @@ int AttributesImpl::getIndex(const XMLString& namespaceURI, const XMLString& loc
|
||||
|
||||
void AttributesImpl::setValue(int i, const XMLString& value)
|
||||
{
|
||||
poco_assert (i < _attributes.size());
|
||||
_attributes[i].value = value;
|
||||
_attributes[i].specified = true;
|
||||
poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
|
||||
_attributes[i].value = value;
|
||||
_attributes[i].specified = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -151,10 +151,10 @@ void AttributesImpl::setAttributes(const Attributes& attributes)
|
||||
|
||||
void AttributesImpl::setAttribute(int i, const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const XMLString& type, const XMLString& value)
|
||||
{
|
||||
poco_assert (i < _attributes.size());
|
||||
_attributes[i].namespaceURI = namespaceURI;
|
||||
_attributes[i].localName = localName;
|
||||
_attributes[i].qname = qname;
|
||||
poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
|
||||
_attributes[i].namespaceURI = namespaceURI;
|
||||
_attributes[i].localName = localName;
|
||||
_attributes[i].qname = qname;
|
||||
_attributes[i].type = type;
|
||||
_attributes[i].value = value;
|
||||
_attributes[i].specified = true;
|
||||
@@ -251,29 +251,29 @@ void AttributesImpl::reserve(std::size_t capacity)
|
||||
|
||||
void AttributesImpl::setLocalName(int i, const XMLString& localName)
|
||||
{
|
||||
poco_assert (i < _attributes.size());
|
||||
_attributes[i].localName = localName;
|
||||
poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
|
||||
_attributes[i].localName = localName;
|
||||
}
|
||||
|
||||
|
||||
void AttributesImpl::setQName(int i, const XMLString& qname)
|
||||
{
|
||||
poco_assert (i < _attributes.size());
|
||||
_attributes[i].qname = qname;
|
||||
poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
|
||||
_attributes[i].qname = qname;
|
||||
}
|
||||
|
||||
|
||||
void AttributesImpl::setType(int i, const XMLString& type)
|
||||
{
|
||||
poco_assert (i < _attributes.size());
|
||||
_attributes[i].type = type;
|
||||
poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
|
||||
_attributes[i].type = type;
|
||||
}
|
||||
|
||||
|
||||
void AttributesImpl::setURI(int i, const XMLString& namespaceURI)
|
||||
{
|
||||
poco_assert (i < _attributes.size());
|
||||
_attributes[i].namespaceURI = namespaceURI;
|
||||
poco_assert (0 <= i && i < static_cast<int>(_attributes.size()));
|
||||
_attributes[i].namespaceURI = namespaceURI;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,15 +46,15 @@ namespace Poco {
|
||||
namespace XML {
|
||||
|
||||
|
||||
const XMLString DOMParser::FEATURE_WHITESPACE = toXMLString("http://www.appinf.com/features/no-whitespace-in-element-content");
|
||||
const XMLString DOMParser::FEATURE_FILTER_WHITESPACE = toXMLString("http://www.appinf.com/features/no-whitespace-in-element-content");
|
||||
|
||||
|
||||
DOMParser::DOMParser(NamePool* pNamePool):
|
||||
_pNamePool(pNamePool),
|
||||
_whitespace(true)
|
||||
_pNamePool(pNamePool),
|
||||
_filterWhitespace(false)
|
||||
{
|
||||
if (_pNamePool) _pNamePool->duplicate();
|
||||
_saxParser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
|
||||
if (_pNamePool) _pNamePool->duplicate();
|
||||
_saxParser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
|
||||
_saxParser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true);
|
||||
}
|
||||
|
||||
@@ -85,51 +85,51 @@ void DOMParser::addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding
|
||||
|
||||
void DOMParser::setFeature(const XMLString& name, bool state)
|
||||
{
|
||||
if (name == FEATURE_WHITESPACE)
|
||||
_whitespace = state;
|
||||
else
|
||||
_saxParser.setFeature(name, state);
|
||||
if (name == FEATURE_FILTER_WHITESPACE)
|
||||
_filterWhitespace = state;
|
||||
else
|
||||
_saxParser.setFeature(name, state);
|
||||
}
|
||||
|
||||
|
||||
bool DOMParser::getFeature(const XMLString& name) const
|
||||
{
|
||||
if (name == FEATURE_WHITESPACE)
|
||||
return _whitespace;
|
||||
else
|
||||
return _saxParser.getFeature(name);
|
||||
if (name == FEATURE_FILTER_WHITESPACE)
|
||||
return _filterWhitespace;
|
||||
else
|
||||
return _saxParser.getFeature(name);
|
||||
}
|
||||
|
||||
|
||||
Document* DOMParser::parse(const XMLString& uri)
|
||||
{
|
||||
if (_whitespace)
|
||||
{
|
||||
DOMBuilder builder(_saxParser, _pNamePool);
|
||||
return builder.parse(uri);
|
||||
}
|
||||
else
|
||||
{
|
||||
WhitespaceFilter filter(&_saxParser);
|
||||
DOMBuilder builder(filter, _pNamePool);
|
||||
return builder.parse(uri);
|
||||
}
|
||||
if (_filterWhitespace)
|
||||
{
|
||||
WhitespaceFilter filter(&_saxParser);
|
||||
DOMBuilder builder(filter, _pNamePool);
|
||||
return builder.parse(uri);
|
||||
}
|
||||
else
|
||||
{
|
||||
DOMBuilder builder(_saxParser, _pNamePool);
|
||||
return builder.parse(uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Document* DOMParser::parse(InputSource* pInputSource)
|
||||
{
|
||||
if (_whitespace)
|
||||
{
|
||||
DOMBuilder builder(_saxParser, _pNamePool);
|
||||
return builder.parse(pInputSource);
|
||||
}
|
||||
else
|
||||
{
|
||||
WhitespaceFilter filter(&_saxParser);
|
||||
DOMBuilder builder(filter, _pNamePool);
|
||||
return builder.parse(pInputSource);
|
||||
}
|
||||
if (_filterWhitespace)
|
||||
{
|
||||
WhitespaceFilter filter(&_saxParser);
|
||||
DOMBuilder builder(filter, _pNamePool);
|
||||
return builder.parse(pInputSource);
|
||||
}
|
||||
else
|
||||
{
|
||||
DOMBuilder builder(_saxParser, _pNamePool);
|
||||
return builder.parse(pInputSource);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -141,17 +141,17 @@ Document* DOMParser::parseString(const std::string& xml)
|
||||
|
||||
Document* DOMParser::parseMemory(const char* xml, std::size_t size)
|
||||
{
|
||||
if (_whitespace)
|
||||
{
|
||||
DOMBuilder builder(_saxParser, _pNamePool);
|
||||
return builder.parseMemoryNP(xml, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
WhitespaceFilter filter(&_saxParser);
|
||||
DOMBuilder builder(filter, _pNamePool);
|
||||
return builder.parseMemoryNP(xml, size);
|
||||
}
|
||||
if (_filterWhitespace)
|
||||
{
|
||||
WhitespaceFilter filter(&_saxParser);
|
||||
DOMBuilder builder(filter, _pNamePool);
|
||||
return builder.parseMemoryNP(xml, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
DOMBuilder builder(_saxParser, _pNamePool);
|
||||
return builder.parseMemoryNP(xml, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,8 +53,9 @@ namespace XML {
|
||||
|
||||
|
||||
DOMWriter::DOMWriter():
|
||||
_pTextEncoding(0),
|
||||
_options(0)
|
||||
_pTextEncoding(0),
|
||||
_options(0),
|
||||
_indent("\t")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -83,17 +84,24 @@ void DOMWriter::setNewLine(const std::string& newLine)
|
||||
}
|
||||
|
||||
|
||||
void DOMWriter::setIndent(const std::string& indent)
|
||||
{
|
||||
_indent = indent;
|
||||
}
|
||||
|
||||
|
||||
void DOMWriter::writeNode(XMLByteOutputStream& ostr, const Node* pNode)
|
||||
{
|
||||
poco_check_ptr (pNode);
|
||||
poco_check_ptr (pNode);
|
||||
|
||||
bool isFragment = pNode->nodeType() != Node::DOCUMENT_NODE;
|
||||
|
||||
XMLWriter writer(ostr, _options, _encodingName, _pTextEncoding);
|
||||
writer.setNewLine(_newLine);
|
||||
|
||||
DOMSerializer serializer;
|
||||
serializer.setContentHandler(&writer);
|
||||
XMLWriter writer(ostr, _options, _encodingName, _pTextEncoding);
|
||||
writer.setNewLine(_newLine);
|
||||
writer.setIndent(_indent);
|
||||
|
||||
DOMSerializer serializer;
|
||||
serializer.setContentHandler(&writer);
|
||||
serializer.setDTDHandler(&writer);
|
||||
serializer.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<LexicalHandler*>(&writer));
|
||||
if (isFragment) writer.startFragment();
|
||||
|
||||
@@ -76,13 +76,17 @@ unsigned long ElementsByTagNameList::length() const
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static const XMLString asterisk = toXMLString("*");
|
||||
}
|
||||
|
||||
|
||||
Node* ElementsByTagNameList::find(const Node* pParent, unsigned long index) const
|
||||
{
|
||||
static const XMLString asterisk = toXMLString("*");
|
||||
if (!pParent) return 0;
|
||||
|
||||
if (!pParent) return 0;
|
||||
|
||||
// preorder search
|
||||
// preorder search
|
||||
Node* pCur = pParent->firstChild();
|
||||
while (pCur)
|
||||
{
|
||||
@@ -141,11 +145,9 @@ unsigned long ElementsByTagNameListNS::length() const
|
||||
|
||||
Node* ElementsByTagNameListNS::find(const Node* pParent, unsigned long index) const
|
||||
{
|
||||
static const XMLString asterisk = toXMLString("*");
|
||||
if (!pParent) return 0;
|
||||
|
||||
if (!pParent) return 0;
|
||||
|
||||
// preorder search
|
||||
// preorder search
|
||||
Node* pCur = pParent->firstChild();
|
||||
while (pCur)
|
||||
{
|
||||
|
||||
@@ -143,7 +143,7 @@ bool Name::equals(const XMLString& qname, const XMLString& namespaceURI, const X
|
||||
|
||||
bool Name::equalsWeakly(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const
|
||||
{
|
||||
return _qname == qname && !qname.empty() || _namespaceURI == namespaceURI && _localName == localName && !_localName.empty();
|
||||
return (_qname == qname && !qname.empty()) || (_namespaceURI == namespaceURI && _localName == localName && !_localName.empty());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -109,12 +109,13 @@ ParserEngine::ParserEngine():
|
||||
_parser(0),
|
||||
_pBuffer(0),
|
||||
_encodingSpecified(false),
|
||||
_expandInternalEntities(true),
|
||||
_externalGeneralEntities(false),
|
||||
_externalParameterEntities(false),
|
||||
_pNamespaceStrategy(new NoNamespacesStrategy()),
|
||||
_pEntityResolver(0),
|
||||
_pDTDHandler(0),
|
||||
_expandInternalEntities(true),
|
||||
_externalGeneralEntities(false),
|
||||
_externalParameterEntities(false),
|
||||
_enablePartialReads(false),
|
||||
_pNamespaceStrategy(new NoNamespacesStrategy()),
|
||||
_pEntityResolver(0),
|
||||
_pDTDHandler(0),
|
||||
_pDeclHandler(0),
|
||||
_pContentHandler(0),
|
||||
_pLexicalHandler(0),
|
||||
@@ -128,12 +129,13 @@ ParserEngine::ParserEngine(const XMLString& encoding):
|
||||
_pBuffer(0),
|
||||
_encodingSpecified(true),
|
||||
_encoding(encoding),
|
||||
_expandInternalEntities(true),
|
||||
_externalGeneralEntities(false),
|
||||
_externalParameterEntities(false),
|
||||
_pNamespaceStrategy(new NoNamespacesStrategy()),
|
||||
_pEntityResolver(0),
|
||||
_pDTDHandler(0),
|
||||
_expandInternalEntities(true),
|
||||
_externalGeneralEntities(false),
|
||||
_externalParameterEntities(false),
|
||||
_enablePartialReads(false),
|
||||
_pNamespaceStrategy(new NoNamespacesStrategy()),
|
||||
_pEntityResolver(0),
|
||||
_pDTDHandler(0),
|
||||
_pDeclHandler(0),
|
||||
_pContentHandler(0),
|
||||
_pLexicalHandler(0),
|
||||
@@ -232,9 +234,15 @@ void ParserEngine::setErrorHandler(ErrorHandler* pErrorHandler)
|
||||
}
|
||||
|
||||
|
||||
void ParserEngine::setEnablePartialReads(bool flag)
|
||||
{
|
||||
_enablePartialReads = flag;
|
||||
}
|
||||
|
||||
|
||||
void ParserEngine::parse(InputSource* pInputSource)
|
||||
{
|
||||
init();
|
||||
init();
|
||||
resetContext();
|
||||
pushContext(_parser, pInputSource);
|
||||
if (_pContentHandler) _pContentHandler->setDocumentLocator(this);
|
||||
@@ -266,41 +274,35 @@ void ParserEngine::parse(const char* pBuffer, std::size_t size)
|
||||
|
||||
void ParserEngine::parseByteInputStream(XMLByteInputStream& istr)
|
||||
{
|
||||
istr.read(_pBuffer, PARSE_BUFFER_SIZE);
|
||||
int n = static_cast<int>(istr.gcount());
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(_parser, _pBuffer, n, 0))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
if (istr.good())
|
||||
{
|
||||
istr.read(_pBuffer, PARSE_BUFFER_SIZE);
|
||||
n = static_cast<int>(istr.gcount());
|
||||
}
|
||||
else n = 0;
|
||||
}
|
||||
if (!XML_Parse(_parser, _pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
std::streamsize n = readBytes(istr, _pBuffer, PARSE_BUFFER_SIZE);
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(_parser, _pBuffer, static_cast<int>(n), 0))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
if (istr.good())
|
||||
n = readBytes(istr, _pBuffer, PARSE_BUFFER_SIZE);
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
if (!XML_Parse(_parser, _pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
}
|
||||
|
||||
|
||||
void ParserEngine::parseCharInputStream(XMLCharInputStream& istr)
|
||||
{
|
||||
istr.read(reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
int n = static_cast<int>(istr.gcount());
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(_parser, _pBuffer, n*sizeof(XMLChar), 0))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
if (istr.good())
|
||||
{
|
||||
istr.read(reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
n = static_cast<int>(istr.gcount());
|
||||
}
|
||||
else n = 0;
|
||||
}
|
||||
if (!XML_Parse(_parser, _pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
std::streamsize n = readChars(istr, reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(_parser, _pBuffer, static_cast<int>(n*sizeof(XMLChar)), 0))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
if (istr.good())
|
||||
n = readChars(istr, reinterpret_cast<XMLChar*>(_pBuffer), PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
if (!XML_Parse(_parser, _pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(_parser));
|
||||
}
|
||||
|
||||
|
||||
@@ -318,24 +320,21 @@ void ParserEngine::parseExternal(XML_Parser extParser, InputSource* pInputSource
|
||||
|
||||
void ParserEngine::parseExternalByteInputStream(XML_Parser extParser, XMLByteInputStream& istr)
|
||||
{
|
||||
char *pBuffer = new char[PARSE_BUFFER_SIZE];
|
||||
try
|
||||
{
|
||||
istr.read(pBuffer, PARSE_BUFFER_SIZE);
|
||||
int n = static_cast<int>(istr.gcount());
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(extParser, pBuffer, n, 0))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
if (istr.good())
|
||||
{
|
||||
istr.read(pBuffer, PARSE_BUFFER_SIZE);
|
||||
n = static_cast<int>(istr.gcount());
|
||||
}
|
||||
else n = 0;
|
||||
}
|
||||
if (!XML_Parse(extParser, pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
char *pBuffer = new char[PARSE_BUFFER_SIZE];
|
||||
try
|
||||
{
|
||||
std::streamsize n = readBytes(istr, pBuffer, PARSE_BUFFER_SIZE);
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(extParser, pBuffer, static_cast<int>(n), 0))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
if (istr.good())
|
||||
n = readBytes(istr, pBuffer, PARSE_BUFFER_SIZE);
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
if (!XML_Parse(extParser, pBuffer, 0, 1))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -348,24 +347,21 @@ void ParserEngine::parseExternalByteInputStream(XML_Parser extParser, XMLByteInp
|
||||
|
||||
void ParserEngine::parseExternalCharInputStream(XML_Parser extParser, XMLCharInputStream& istr)
|
||||
{
|
||||
XMLChar *pBuffer = new XMLChar[PARSE_BUFFER_SIZE/sizeof(XMLChar)];
|
||||
try
|
||||
{
|
||||
istr.read(pBuffer, PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
int n = static_cast<int>(istr.gcount());
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), n*sizeof(XMLChar), 0))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
if (istr.good())
|
||||
{
|
||||
istr.read(pBuffer, PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
n = static_cast<int>(istr.gcount());
|
||||
}
|
||||
else n = 0;
|
||||
}
|
||||
if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), 0, 1))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
XMLChar *pBuffer = new XMLChar[PARSE_BUFFER_SIZE/sizeof(XMLChar)];
|
||||
try
|
||||
{
|
||||
std::streamsize n = readChars(istr, pBuffer, PARSE_BUFFER_SIZE/sizeof(XMLChar));
|
||||
while (n > 0)
|
||||
{
|
||||
if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), static_cast<int>(n*sizeof(XMLChar)), 0))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
if (istr.good())
|
||||
n = readChars(istr, pBuffer, static_cast<int>(PARSE_BUFFER_SIZE/sizeof(XMLChar)));
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
if (!XML_Parse(extParser, reinterpret_cast<char*>(pBuffer), 0, 1))
|
||||
handleError(XML_GetErrorCode(extParser));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -376,9 +372,49 @@ void ParserEngine::parseExternalCharInputStream(XML_Parser extParser, XMLCharInp
|
||||
}
|
||||
|
||||
|
||||
std::streamsize ParserEngine::readBytes(XMLByteInputStream& istr, char* pBuffer, std::streamsize bufferSize)
|
||||
{
|
||||
if (_enablePartialReads)
|
||||
{
|
||||
istr.read(pBuffer, 1);
|
||||
if (istr.gcount() == 1)
|
||||
{
|
||||
std::streamsize n = istr.readsome(pBuffer + 1, bufferSize - 1);
|
||||
return n + 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
istr.read(pBuffer, bufferSize);
|
||||
return istr.gcount();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::streamsize ParserEngine::readChars(XMLCharInputStream& istr, XMLChar* pBuffer, std::streamsize bufferSize)
|
||||
{
|
||||
if (_enablePartialReads)
|
||||
{
|
||||
istr.read(pBuffer, 1);
|
||||
if (istr.gcount() == 1)
|
||||
{
|
||||
std::streamsize n = istr.readsome(pBuffer + 1, bufferSize - 1);
|
||||
return n + 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
istr.read(pBuffer, bufferSize);
|
||||
return istr.gcount();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XMLString ParserEngine::getPublicId() const
|
||||
{
|
||||
return locator().getPublicId();
|
||||
return locator().getPublicId();
|
||||
}
|
||||
|
||||
|
||||
@@ -400,12 +436,17 @@ int ParserEngine::getColumnNumber() const
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static LocatorImpl nullLocator;
|
||||
}
|
||||
|
||||
|
||||
const Locator& ParserEngine::locator() const
|
||||
{
|
||||
static LocatorImpl nullLocator;
|
||||
if (_context.empty())
|
||||
return nullLocator;
|
||||
else
|
||||
if (_context.empty())
|
||||
return nullLocator;
|
||||
else
|
||||
return *_context.back();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,9 +46,12 @@ namespace Poco {
|
||||
namespace XML {
|
||||
|
||||
|
||||
const XMLString SAXParser::FEATURE_PARTIAL_READS = toXMLString("http://www.appinf.com/features/enable-partial-reads");
|
||||
|
||||
|
||||
SAXParser::SAXParser():
|
||||
_namespaces(true),
|
||||
_namespacePrefixes(false)
|
||||
_namespaces(true),
|
||||
_namespacePrefixes(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -141,10 +144,12 @@ void SAXParser::setFeature(const XMLString& featureId, bool state)
|
||||
else if (featureId == XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES)
|
||||
_engine.setExternalParameterEntities(state);
|
||||
else if (featureId == XMLReader::FEATURE_NAMESPACES)
|
||||
_namespaces = state;
|
||||
else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES)
|
||||
_namespacePrefixes = state;
|
||||
else throw SAXNotRecognizedException(fromXMLString(featureId));
|
||||
_namespaces = state;
|
||||
else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES)
|
||||
_namespacePrefixes = state;
|
||||
else if (featureId == FEATURE_PARTIAL_READS)
|
||||
_engine.setEnablePartialReads(state);
|
||||
else throw SAXNotRecognizedException(fromXMLString(featureId));
|
||||
}
|
||||
|
||||
|
||||
@@ -157,10 +162,12 @@ bool SAXParser::getFeature(const XMLString& featureId) const
|
||||
else if (featureId == XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES)
|
||||
return _engine.getExternalParameterEntities();
|
||||
else if (featureId == XMLReader::FEATURE_NAMESPACES)
|
||||
return _namespaces;
|
||||
else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES)
|
||||
return _namespacePrefixes;
|
||||
else throw SAXNotRecognizedException(fromXMLString(featureId));
|
||||
return _namespaces;
|
||||
else if (featureId == XMLReader::FEATURE_NAMESPACE_PREFIXES)
|
||||
return _namespacePrefixes;
|
||||
else if (featureId == FEATURE_PARTIAL_READS)
|
||||
return _engine.getEnablePartialReads();
|
||||
else throw SAXNotRecognizedException(fromXMLString(featureId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ const std::string XMLWriter::MARKUP_APOSENC = "'";
|
||||
const std::string XMLWriter::MARKUP_AMPENC = "&";
|
||||
const std::string XMLWriter::MARKUP_LTENC = "<";
|
||||
const std::string XMLWriter::MARKUP_GTENC = ">";
|
||||
const std::string XMLWriter::MARKUP_TABENC = "	";
|
||||
const std::string XMLWriter::MARKUP_CRENC = "
";
|
||||
const std::string XMLWriter::MARKUP_LFENC = "
";
|
||||
const std::string XMLWriter::MARKUP_LT = "<";
|
||||
const std::string XMLWriter::MARKUP_GT = ">";
|
||||
const std::string XMLWriter::MARKUP_SLASHGT = "/>";
|
||||
@@ -87,13 +90,15 @@ XMLWriter::XMLWriter(XMLByteOutputStream& str, int options):
|
||||
_inFragment(false),
|
||||
_inCDATA(false),
|
||||
_inDTD(false),
|
||||
_inInternalDTD(false),
|
||||
_contentWritten(false),
|
||||
_unclosedStartTag(false),
|
||||
_prefix(0)
|
||||
_inInternalDTD(false),
|
||||
_contentWritten(false),
|
||||
_unclosedStartTag(false),
|
||||
_prefix(0),
|
||||
_nsContextPushed(false),
|
||||
_indent(MARKUP_TAB)
|
||||
{
|
||||
_pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *_pOutEncoding);
|
||||
setNewLine(NEWLINE_DEFAULT);
|
||||
_pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *_pOutEncoding);
|
||||
setNewLine((_options & CANONICAL_XML) ? NEWLINE_LF : NEWLINE_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,13 +113,15 @@ XMLWriter::XMLWriter(XMLByteOutputStream& str, int options, const std::string& e
|
||||
_inFragment(false),
|
||||
_inCDATA(false),
|
||||
_inDTD(false),
|
||||
_inInternalDTD(false),
|
||||
_contentWritten(false),
|
||||
_unclosedStartTag(false),
|
||||
_prefix(0)
|
||||
_inInternalDTD(false),
|
||||
_contentWritten(false),
|
||||
_unclosedStartTag(false),
|
||||
_prefix(0),
|
||||
_nsContextPushed(false),
|
||||
_indent(MARKUP_TAB)
|
||||
{
|
||||
_pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, textEncoding);
|
||||
setNewLine(NEWLINE_DEFAULT);
|
||||
_pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, textEncoding);
|
||||
setNewLine((_options & CANONICAL_XML) ? NEWLINE_LF : NEWLINE_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,22 +136,24 @@ XMLWriter::XMLWriter(XMLByteOutputStream& str, int options, const std::string& e
|
||||
_inFragment(false),
|
||||
_inCDATA(false),
|
||||
_inDTD(false),
|
||||
_inInternalDTD(false),
|
||||
_contentWritten(false),
|
||||
_unclosedStartTag(false),
|
||||
_prefix(0)
|
||||
_inInternalDTD(false),
|
||||
_contentWritten(false),
|
||||
_unclosedStartTag(false),
|
||||
_prefix(0),
|
||||
_nsContextPushed(false),
|
||||
_indent(MARKUP_TAB)
|
||||
{
|
||||
if (pTextEncoding)
|
||||
{
|
||||
if (pTextEncoding)
|
||||
{
|
||||
_pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *pTextEncoding);
|
||||
}
|
||||
else
|
||||
{
|
||||
_encoding = "UTF-8";
|
||||
_pOutEncoding = new Poco::UTF8Encoding;
|
||||
_pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *_pOutEncoding);
|
||||
}
|
||||
setNewLine(NEWLINE_DEFAULT);
|
||||
_pOutEncoding = new Poco::UTF8Encoding;
|
||||
_pTextConverter = new Poco::OutputStreamConverter(str, *_pInEncoding, *_pOutEncoding);
|
||||
}
|
||||
setNewLine((_options & CANONICAL_XML) ? NEWLINE_LF : NEWLINE_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
@@ -181,9 +190,21 @@ const std::string& XMLWriter::getNewLine() const
|
||||
}
|
||||
|
||||
|
||||
void XMLWriter::setIndent(const std::string& indent)
|
||||
{
|
||||
_indent = indent;
|
||||
}
|
||||
|
||||
|
||||
const std::string& XMLWriter::getIndent() const
|
||||
{
|
||||
return _indent;
|
||||
}
|
||||
|
||||
|
||||
void XMLWriter::startDocument()
|
||||
{
|
||||
if (_depth != -1)
|
||||
if (_depth != -1)
|
||||
throw XMLException("Cannot start a document in another document");
|
||||
|
||||
_inFragment = false;
|
||||
@@ -245,8 +266,8 @@ void XMLWriter::endFragment()
|
||||
|
||||
void XMLWriter::startElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname)
|
||||
{
|
||||
static const AttributesImpl attributes;
|
||||
startElement(namespaceURI, localName, qname, attributes);
|
||||
const AttributesImpl attributes;
|
||||
startElement(namespaceURI, localName, qname, attributes);
|
||||
}
|
||||
|
||||
|
||||
@@ -284,8 +305,8 @@ void XMLWriter::endElement(const XMLString& namespaceURI, const XMLString& local
|
||||
|
||||
void XMLWriter::emptyElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname)
|
||||
{
|
||||
static const AttributesImpl attributes;
|
||||
emptyElement(namespaceURI, localName, qname, attributes);
|
||||
const AttributesImpl attributes;
|
||||
emptyElement(namespaceURI, localName, qname, attributes);
|
||||
}
|
||||
|
||||
|
||||
@@ -377,17 +398,21 @@ void XMLWriter::processingInstruction(const XMLString& target, const XMLString&
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static const XMLString CDATA = toXMLString("CDATA");
|
||||
}
|
||||
|
||||
|
||||
void XMLWriter::dataElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname,
|
||||
const XMLString& data,
|
||||
const XMLString& attr1, const XMLString& value1,
|
||||
const XMLString& attr2, const XMLString& value2,
|
||||
const XMLString& attr3, const XMLString& value3)
|
||||
const XMLString& attr1, const XMLString& value1,
|
||||
const XMLString& attr2, const XMLString& value2,
|
||||
const XMLString& attr3, const XMLString& value3)
|
||||
{
|
||||
static const XMLString CDATA = toXMLString("CDATA");
|
||||
|
||||
AttributesImpl attributes;
|
||||
if (!attr1.empty()) attributes.addAttribute(XMLString(), XMLString(), attr1, CDATA, value1);
|
||||
if (!attr2.empty()) attributes.addAttribute(XMLString(), XMLString(), attr2, CDATA, value2);
|
||||
AttributesImpl attributes;
|
||||
if (!attr1.empty()) attributes.addAttribute(XMLString(), XMLString(), attr1, CDATA, value1);
|
||||
if (!attr2.empty()) attributes.addAttribute(XMLString(), XMLString(), attr2, CDATA, value2);
|
||||
if (!attr3.empty()) attributes.addAttribute(XMLString(), XMLString(), attr3, CDATA, value3);
|
||||
if (data.empty())
|
||||
{
|
||||
@@ -404,15 +429,21 @@ void XMLWriter::dataElement(const XMLString& namespaceURI, const XMLString& loca
|
||||
|
||||
void XMLWriter::startPrefixMapping(const XMLString& prefix, const XMLString& namespaceURI)
|
||||
{
|
||||
if (prefix != NamespaceSupport::XML_NAMESPACE_PREFIX)
|
||||
_namespaces.declarePrefix(prefix, namespaceURI);
|
||||
if (prefix != NamespaceSupport::XML_NAMESPACE_PREFIX)
|
||||
{
|
||||
if (!_nsContextPushed)
|
||||
{
|
||||
_namespaces.pushContext();
|
||||
_nsContextPushed = true;
|
||||
}
|
||||
_namespaces.declarePrefix(prefix, namespaceURI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XMLWriter::endPrefixMapping(const XMLString& prefix)
|
||||
{
|
||||
if (prefix != NamespaceSupport::XML_NAMESPACE_PREFIX)
|
||||
_namespaces.undeclarePrefix(prefix);
|
||||
// Note: prefix removed by popContext() at element closing tag
|
||||
}
|
||||
|
||||
|
||||
@@ -502,13 +533,13 @@ void XMLWriter::notationDecl(const XMLString& name, const XMLString* publicId, c
|
||||
writeMarkup(" [");
|
||||
_inInternalDTD = true;
|
||||
}
|
||||
if (_options & PRETTY_PRINT)
|
||||
{
|
||||
writeNewLine();
|
||||
writeMarkup(MARKUP_TAB);
|
||||
}
|
||||
writeMarkup("<!NOTATION ");
|
||||
writeXML(name);
|
||||
if (_options & PRETTY_PRINT)
|
||||
{
|
||||
writeNewLine();
|
||||
writeMarkup(_indent);
|
||||
}
|
||||
writeMarkup("<!NOTATION ");
|
||||
writeXML(name);
|
||||
if (systemId && !systemId->empty())
|
||||
{
|
||||
writeMarkup(" SYSTEM \"");
|
||||
@@ -533,13 +564,13 @@ void XMLWriter::unparsedEntityDecl(const XMLString& name, const XMLString* publi
|
||||
writeMarkup(" [");
|
||||
_inInternalDTD = true;
|
||||
}
|
||||
if (_options & PRETTY_PRINT)
|
||||
{
|
||||
writeNewLine();
|
||||
writeMarkup(MARKUP_TAB);
|
||||
}
|
||||
writeMarkup("<!ENTITY ");
|
||||
writeXML(name);
|
||||
if (_options & PRETTY_PRINT)
|
||||
{
|
||||
writeNewLine();
|
||||
writeMarkup(_indent);
|
||||
}
|
||||
writeMarkup("<!ENTITY ");
|
||||
writeXML(name);
|
||||
if (!systemId.empty())
|
||||
{
|
||||
writeMarkup(" SYSTEM \"");
|
||||
@@ -573,10 +604,16 @@ void XMLWriter::prettyPrint() const
|
||||
|
||||
void XMLWriter::writeStartElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes)
|
||||
{
|
||||
++_elementCount;
|
||||
writeMarkup(MARKUP_LT);
|
||||
if (!localName.empty() && (qname.empty() || localName == qname))
|
||||
{
|
||||
if (!_nsContextPushed)
|
||||
_namespaces.pushContext();
|
||||
_nsContextPushed = false;
|
||||
++_elementCount;
|
||||
|
||||
declareAttributeNamespaces(attributes);
|
||||
|
||||
writeMarkup(MARKUP_LT);
|
||||
if (!localName.empty() && (qname.empty() || localName == qname))
|
||||
{
|
||||
XMLString prefix;
|
||||
if (!namespaceURI.empty() && !_namespaces.isMapped(namespaceURI))
|
||||
{
|
||||
@@ -602,31 +639,34 @@ void XMLWriter::writeStartElement(const XMLString& namespaceURI, const XMLString
|
||||
_namespaces.declarePrefix(prefix, namespaceURI);
|
||||
}
|
||||
writeName(prefix, localName);
|
||||
}
|
||||
else throw XMLException("Tag mismatch", nameToString(localName, qname));
|
||||
}
|
||||
else throw XMLException("Tag mismatch", nameToString(localName, qname));
|
||||
|
||||
declareAttributeNamespaces(attributes);
|
||||
AttributeMap attributeMap;
|
||||
addNamespaceAttributes(attributeMap);
|
||||
addAttributes(attributeMap, attributes, namespaceURI);
|
||||
writeAttributes(attributeMap);
|
||||
_unclosedStartTag = true;
|
||||
_namespaces.pushContext();
|
||||
AttributeMap attributeMap;
|
||||
addNamespaceAttributes(attributeMap);
|
||||
addAttributes(attributeMap, attributes, namespaceURI);
|
||||
writeAttributes(attributeMap);
|
||||
_unclosedStartTag = true;
|
||||
}
|
||||
|
||||
|
||||
void XMLWriter::writeEndElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname)
|
||||
{
|
||||
if (_unclosedStartTag)
|
||||
{
|
||||
writeMarkup(MARKUP_SLASHGT);
|
||||
_unclosedStartTag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
writeMarkup(MARKUP_LTSLASH);
|
||||
if (!localName.empty())
|
||||
{
|
||||
if (_unclosedStartTag && !(_options & CANONICAL_XML))
|
||||
{
|
||||
writeMarkup(MARKUP_SLASHGT);
|
||||
_unclosedStartTag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_unclosedStartTag)
|
||||
{
|
||||
writeMarkup(MARKUP_GT);
|
||||
_unclosedStartTag = false;
|
||||
}
|
||||
writeMarkup(MARKUP_LTSLASH);
|
||||
if (!localName.empty())
|
||||
{
|
||||
XMLString prefix = _namespaces.getPrefix(namespaceURI);
|
||||
writeName(prefix, localName);
|
||||
}
|
||||
@@ -666,7 +706,6 @@ void XMLWriter::declareAttributeNamespaces(const Attributes& attributes)
|
||||
_namespaces.declarePrefix(prefix, namespaceURI);
|
||||
}
|
||||
|
||||
|
||||
const XMLString& uri = _namespaces.getURI(prefix);
|
||||
if ((uri.empty() || uri != namespaceURI) && !namespaceURI.empty())
|
||||
{
|
||||
@@ -704,13 +743,13 @@ void XMLWriter::addAttributes(AttributeMap& attributeMap, const Attributes& attr
|
||||
XMLString namespaceURI = attributes.getURI(i);
|
||||
XMLString localName = attributes.getLocalName(i);
|
||||
XMLString qname = attributes.getQName(i);
|
||||
if (!localName.empty())
|
||||
{
|
||||
XMLString prefix;
|
||||
if (namespaceURI != elementNamespaceURI)
|
||||
prefix = _namespaces.getPrefix(namespaceURI);
|
||||
if (!prefix.empty())
|
||||
{
|
||||
if (!localName.empty())
|
||||
{
|
||||
XMLString prefix;
|
||||
if (!namespaceURI.empty())
|
||||
prefix = _namespaces.getPrefix(namespaceURI);
|
||||
if (!prefix.empty())
|
||||
{
|
||||
qname = prefix;
|
||||
qname.append(toXMLString(MARKUP_COLON));
|
||||
}
|
||||
@@ -724,20 +763,52 @@ void XMLWriter::addAttributes(AttributeMap& attributeMap, const Attributes& attr
|
||||
|
||||
void XMLWriter::writeAttributes(const AttributeMap& attributeMap)
|
||||
{
|
||||
for (AttributeMap::const_iterator it = attributeMap.begin(); it != attributeMap.end(); ++it)
|
||||
{
|
||||
writeMarkup(MARKUP_SPACE);
|
||||
writeXML(it->first);
|
||||
writeMarkup(MARKUP_EQQUOT);
|
||||
characters(it->second);
|
||||
writeMarkup(MARKUP_QUOT);
|
||||
}
|
||||
for (AttributeMap::const_iterator it = attributeMap.begin(); it != attributeMap.end(); ++it)
|
||||
{
|
||||
if ((_options & PRETTY_PRINT) && (_options & PRETTY_PRINT_ATTRIBUTES))
|
||||
{
|
||||
writeNewLine();
|
||||
writeIndent(_depth + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeMarkup(MARKUP_SPACE);
|
||||
}
|
||||
writeXML(it->first);
|
||||
writeMarkup(MARKUP_EQQUOT);
|
||||
for (XMLString::const_iterator itc = it->second.begin(); itc != it->second.end(); ++itc)
|
||||
{
|
||||
XMLChar c = *itc;
|
||||
switch (c)
|
||||
{
|
||||
case '"': writeMarkup(MARKUP_QUOTENC); break;
|
||||
case '\'': writeMarkup(MARKUP_APOSENC); break;
|
||||
case '&': writeMarkup(MARKUP_AMPENC); break;
|
||||
case '<': writeMarkup(MARKUP_LTENC); break;
|
||||
case '>': writeMarkup(MARKUP_GTENC); break;
|
||||
case '\t': writeMarkup(MARKUP_TABENC); break;
|
||||
case '\r': writeMarkup(MARKUP_CRENC); break;
|
||||
case '\n': writeMarkup(MARKUP_LFENC); break;
|
||||
default:
|
||||
if (c >= 0 && c < 32)
|
||||
throw XMLException("Invalid character token.");
|
||||
else
|
||||
writeXML(c);
|
||||
}
|
||||
}
|
||||
writeMarkup(MARKUP_QUOT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XMLWriter::writeMarkup(const std::string& str) const
|
||||
{
|
||||
_pTextConverter->write(str.data(), (int) str.size());
|
||||
#if defined(XML_UNICODE_WCHAR_T)
|
||||
const XMLString xmlString = toXMLString(str);
|
||||
writeXML(xmlString);
|
||||
#else
|
||||
_pTextConverter->write(str.data(), (int) str.size());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -777,8 +848,14 @@ void XMLWriter::writeNewLine() const
|
||||
|
||||
void XMLWriter::writeIndent() const
|
||||
{
|
||||
for (int i = 0; i < _depth; ++i)
|
||||
writeMarkup(MARKUP_TAB);
|
||||
writeIndent(_depth);
|
||||
}
|
||||
|
||||
|
||||
void XMLWriter::writeIndent(int depth) const
|
||||
{
|
||||
for (int i = 0; i < depth; ++i)
|
||||
writeMarkup(_indent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,9 @@
|
||||
#include "Poco/Platform.h"
|
||||
|
||||
|
||||
#if !defined(POCO_VXWORKS)
|
||||
#include <memory.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "winconfig.h"
|
||||
#elif defined(MACOS_CLASSIC)
|
||||
#include "macconfig.h"
|
||||
#elif defined(__amigaos4__)
|
||||
#elif defined(__amigaos__)
|
||||
#include "amigaconfig.h"
|
||||
#elif defined(__WATCOMC__)
|
||||
#include "watcomconfig.h"
|
||||
@@ -327,15 +327,15 @@ processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
|
||||
static enum XML_Error
|
||||
initializeEncoding(XML_Parser parser);
|
||||
static enum XML_Error
|
||||
doProlog(XML_Parser parser, const ENCODING *enc, const char *s,
|
||||
const char *end, int tok, const char *next, const char **nextPtr,
|
||||
doProlog(XML_Parser parser, const ENCODING *enc, const char *s,
|
||||
const char *end, int tok, const char *next, const char **nextPtr,
|
||||
XML_Bool haveMore);
|
||||
static enum XML_Error
|
||||
processInternalEntity(XML_Parser parser, ENTITY *entity,
|
||||
processInternalEntity(XML_Parser parser, ENTITY *entity,
|
||||
XML_Bool betweenDecl);
|
||||
static enum XML_Error
|
||||
doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc,
|
||||
const char *start, const char *end, const char **endPtr,
|
||||
const char *start, const char *end, const char **endPtr,
|
||||
XML_Bool haveMore);
|
||||
static enum XML_Error
|
||||
doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr,
|
||||
@@ -353,7 +353,7 @@ static enum XML_Error
|
||||
addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
|
||||
const XML_Char *uri, BINDING **bindingsPtr);
|
||||
static int
|
||||
defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata,
|
||||
defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata,
|
||||
XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser);
|
||||
static enum XML_Error
|
||||
storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata,
|
||||
@@ -670,7 +670,7 @@ XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep)
|
||||
|
||||
static const XML_Char implicitContext[] = {
|
||||
ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p,
|
||||
ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w,
|
||||
ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w,
|
||||
ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD, ASCII_o, ASCII_r, ASCII_g,
|
||||
ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L, ASCII_SLASH, ASCII_1, ASCII_9,
|
||||
ASCII_9, ASCII_8, ASCII_SLASH, ASCII_n, ASCII_a, ASCII_m, ASCII_e,
|
||||
@@ -1459,7 +1459,7 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
|
||||
XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
|
||||
positionPtr = bufferPtr;
|
||||
return XML_STATUS_SUSPENDED;
|
||||
case XML_INITIALIZED:
|
||||
case XML_INITIALIZED:
|
||||
case XML_PARSING:
|
||||
ps_parsing = XML_FINISHED;
|
||||
/* fall through */
|
||||
@@ -1512,16 +1512,12 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
|
||||
? (char *)MALLOC(len * 2)
|
||||
: (char *)REALLOC(buffer, len * 2));
|
||||
if (temp == NULL) {
|
||||
errorCode = XML_ERROR_NO_MEMORY;
|
||||
return XML_STATUS_ERROR;
|
||||
}
|
||||
buffer = temp;
|
||||
if (!buffer) {
|
||||
errorCode = XML_ERROR_NO_MEMORY;
|
||||
eventPtr = eventEndPtr = NULL;
|
||||
processor = errorProcessor;
|
||||
return XML_STATUS_ERROR;
|
||||
}
|
||||
buffer = temp;
|
||||
bufferLim = buffer + len * 2;
|
||||
}
|
||||
memcpy(buffer, end, nLeftOver);
|
||||
@@ -1582,7 +1578,7 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
|
||||
case XML_SUSPENDED:
|
||||
result = XML_STATUS_SUSPENDED;
|
||||
break;
|
||||
case XML_INITIALIZED:
|
||||
case XML_INITIALIZED:
|
||||
case XML_PARSING:
|
||||
if (isFinal) {
|
||||
ps_parsing = XML_FINISHED;
|
||||
@@ -1672,6 +1668,8 @@ XML_GetBuffer(XML_Parser parser, int len)
|
||||
bufferPtr = buffer = newBuf;
|
||||
#endif /* not defined XML_CONTEXT_BYTES */
|
||||
}
|
||||
eventPtr = eventEndPtr = NULL;
|
||||
positionPtr = NULL;
|
||||
}
|
||||
return bufferEnd;
|
||||
}
|
||||
@@ -1729,7 +1727,7 @@ XML_ResumeParser(XML_Parser parser)
|
||||
case XML_SUSPENDED:
|
||||
result = XML_STATUS_SUSPENDED;
|
||||
break;
|
||||
case XML_INITIALIZED:
|
||||
case XML_INITIALIZED:
|
||||
case XML_PARSING:
|
||||
if (ps_finalBuffer) {
|
||||
ps_parsing = XML_FINISHED;
|
||||
@@ -1956,7 +1954,7 @@ XML_GetFeatureList(void)
|
||||
#endif
|
||||
#ifdef XML_LARGE_SIZE
|
||||
{XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0},
|
||||
#endif
|
||||
#endif
|
||||
{XML_FEATURE_END, NULL, 0}
|
||||
};
|
||||
|
||||
@@ -2019,7 +2017,7 @@ contentProcessor(XML_Parser parser,
|
||||
const char *end,
|
||||
const char **endPtr)
|
||||
{
|
||||
enum XML_Error result = doContent(parser, 0, encoding, start, end,
|
||||
enum XML_Error result = doContent(parser, 0, encoding, start, end,
|
||||
endPtr, (XML_Bool)!ps_finalBuffer);
|
||||
if (result == XML_ERROR_NONE) {
|
||||
if (!storeRawNames(parser))
|
||||
@@ -2101,7 +2099,7 @@ externalEntityInitProcessor3(XML_Parser parser,
|
||||
if (result != XML_ERROR_NONE)
|
||||
return result;
|
||||
switch (ps_parsing) {
|
||||
case XML_SUSPENDED:
|
||||
case XML_SUSPENDED:
|
||||
*endPtr = next;
|
||||
return XML_ERROR_NONE;
|
||||
case XML_FINISHED:
|
||||
@@ -2135,7 +2133,7 @@ externalEntityContentProcessor(XML_Parser parser,
|
||||
const char *end,
|
||||
const char **endPtr)
|
||||
{
|
||||
enum XML_Error result = doContent(parser, 1, encoding, start, end,
|
||||
enum XML_Error result = doContent(parser, 1, encoding, start, end,
|
||||
endPtr, (XML_Bool)!ps_finalBuffer);
|
||||
if (result == XML_ERROR_NONE) {
|
||||
if (!storeRawNames(parser))
|
||||
@@ -2154,7 +2152,7 @@ doContent(XML_Parser parser,
|
||||
XML_Bool haveMore)
|
||||
{
|
||||
/* save one level of indirection */
|
||||
DTD * const dtd = _dtd;
|
||||
DTD * const dtd = _dtd;
|
||||
|
||||
const char **eventPP;
|
||||
const char **eventEndPP;
|
||||
@@ -2185,8 +2183,8 @@ doContent(XML_Parser parser,
|
||||
}
|
||||
else if (defaultHandler)
|
||||
reportDefault(parser, enc, s, end);
|
||||
/* We are at the end of the final buffer, should we check for
|
||||
XML_SUSPENDED, XML_FINISHED?
|
||||
/* We are at the end of the final buffer, should we check for
|
||||
XML_SUSPENDED, XML_FINISHED?
|
||||
*/
|
||||
if (startTagLevel == 0)
|
||||
return XML_ERROR_NO_ELEMENTS;
|
||||
@@ -2537,8 +2535,8 @@ doContent(XML_Parser parser,
|
||||
}
|
||||
else if (defaultHandler)
|
||||
reportDefault(parser, enc, s, end);
|
||||
/* We are at the end of the final buffer, should we check for
|
||||
XML_SUSPENDED, XML_FINISHED?
|
||||
/* We are at the end of the final buffer, should we check for
|
||||
XML_SUSPENDED, XML_FINISHED?
|
||||
*/
|
||||
if (startTagLevel == 0) {
|
||||
*eventPP = end;
|
||||
@@ -2550,7 +2548,7 @@ doContent(XML_Parser parser,
|
||||
}
|
||||
*nextPtr = end;
|
||||
return XML_ERROR_NONE;
|
||||
case XML_TOK_DATA_CHARS:
|
||||
case XML_TOK_DATA_CHARS:
|
||||
{
|
||||
XML_CharacterDataHandler charDataHandler = characterDataHandler;
|
||||
if (charDataHandler) {
|
||||
@@ -2590,7 +2588,7 @@ doContent(XML_Parser parser,
|
||||
}
|
||||
*eventPP = s = next;
|
||||
switch (ps_parsing) {
|
||||
case XML_SUSPENDED:
|
||||
case XML_SUSPENDED:
|
||||
*nextPtr = next;
|
||||
return XML_ERROR_NONE;
|
||||
case XML_FINISHED:
|
||||
@@ -2949,27 +2947,27 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
|
||||
static const XML_Char xmlNamespace[] = {
|
||||
ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH,
|
||||
ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD,
|
||||
ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L,
|
||||
ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_X, ASCII_M, ASCII_L,
|
||||
ASCII_SLASH, ASCII_1, ASCII_9, ASCII_9, ASCII_8, ASCII_SLASH,
|
||||
ASCII_n, ASCII_a, ASCII_m, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c,
|
||||
ASCII_e, '\0'
|
||||
};
|
||||
static const int xmlLen =
|
||||
static const int xmlLen =
|
||||
(int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1;
|
||||
static const XML_Char xmlnsNamespace[] = {
|
||||
ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH,
|
||||
ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD,
|
||||
ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0,
|
||||
ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s,
|
||||
ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0,
|
||||
ASCII_0, ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s,
|
||||
ASCII_SLASH, '\0'
|
||||
};
|
||||
static const int xmlnsLen =
|
||||
static const int xmlnsLen =
|
||||
(int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1;
|
||||
|
||||
XML_Bool mustBeXML = XML_FALSE;
|
||||
XML_Bool isXML = XML_TRUE;
|
||||
XML_Bool isXMLNS = XML_TRUE;
|
||||
|
||||
|
||||
BINDING *b;
|
||||
int len;
|
||||
|
||||
@@ -2996,7 +2994,7 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
|
||||
if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len]))
|
||||
isXML = XML_FALSE;
|
||||
|
||||
if (!mustBeXML && isXMLNS
|
||||
if (!mustBeXML && isXMLNS
|
||||
&& (len > xmlnsLen || uri[len] != xmlnsNamespace[len]))
|
||||
isXMLNS = XML_FALSE;
|
||||
}
|
||||
@@ -3207,7 +3205,7 @@ ignoreSectionProcessor(XML_Parser parser,
|
||||
const char *end,
|
||||
const char **endPtr)
|
||||
{
|
||||
enum XML_Error result = doIgnoreSection(parser, encoding, &start, end,
|
||||
enum XML_Error result = doIgnoreSection(parser, encoding, &start, end,
|
||||
endPtr, (XML_Bool)!ps_finalBuffer);
|
||||
if (result != XML_ERROR_NONE)
|
||||
return result;
|
||||
@@ -3489,7 +3487,7 @@ entityValueInitProcessor(XML_Parser parser,
|
||||
const char *next = start;
|
||||
eventPtr = start;
|
||||
|
||||
for (;;) {
|
||||
for (;;) {
|
||||
tok = XmlPrologTok(encoding, start, end, &next);
|
||||
eventEndPtr = next;
|
||||
if (tok <= 0) {
|
||||
@@ -3517,7 +3515,7 @@ entityValueInitProcessor(XML_Parser parser,
|
||||
if (result != XML_ERROR_NONE)
|
||||
return result;
|
||||
switch (ps_parsing) {
|
||||
case XML_SUSPENDED:
|
||||
case XML_SUSPENDED:
|
||||
*nextPtr = next;
|
||||
return XML_ERROR_NONE;
|
||||
case XML_FINISHED:
|
||||
@@ -3582,7 +3580,7 @@ externalParEntProcessor(XML_Parser parser,
|
||||
}
|
||||
|
||||
processor = prologProcessor;
|
||||
return doProlog(parser, encoding, s, end, tok, next,
|
||||
return doProlog(parser, encoding, s, end, tok, next,
|
||||
nextPtr, (XML_Bool)!ps_finalBuffer);
|
||||
}
|
||||
|
||||
@@ -3632,7 +3630,7 @@ prologProcessor(XML_Parser parser,
|
||||
{
|
||||
const char *next = s;
|
||||
int tok = XmlPrologTok(encoding, s, end, &next);
|
||||
return doProlog(parser, encoding, s, end, tok, next,
|
||||
return doProlog(parser, encoding, s, end, tok, next,
|
||||
nextPtr, (XML_Bool)!ps_finalBuffer);
|
||||
}
|
||||
|
||||
@@ -3649,7 +3647,7 @@ doProlog(XML_Parser parser,
|
||||
#ifdef XML_DTD
|
||||
static const XML_Char externalSubsetName[] = { ASCII_HASH , '\0' };
|
||||
#endif /* XML_DTD */
|
||||
static const XML_Char atypeCDATA[] =
|
||||
static const XML_Char atypeCDATA[] =
|
||||
{ ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' };
|
||||
static const XML_Char atypeID[] = { ASCII_I, ASCII_D, '\0' };
|
||||
static const XML_Char atypeIDREF[] =
|
||||
@@ -3670,7 +3668,7 @@ doProlog(XML_Parser parser,
|
||||
static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' };
|
||||
|
||||
/* save one level of indirection */
|
||||
DTD * const dtd = _dtd;
|
||||
DTD * const dtd = _dtd;
|
||||
|
||||
const char **eventPP;
|
||||
const char **eventEndPP;
|
||||
@@ -3703,6 +3701,9 @@ doProlog(XML_Parser parser,
|
||||
return XML_ERROR_UNCLOSED_TOKEN;
|
||||
case XML_TOK_PARTIAL_CHAR:
|
||||
return XML_ERROR_PARTIAL_CHAR;
|
||||
case -XML_TOK_PROLOG_S:
|
||||
tok = -tok;
|
||||
break;
|
||||
case XML_TOK_NONE:
|
||||
#ifdef XML_DTD
|
||||
/* for internal PE NOT referenced between declarations */
|
||||
@@ -3782,15 +3783,17 @@ doProlog(XML_Parser parser,
|
||||
#endif /* XML_DTD */
|
||||
dtd->hasParamEntityRefs = XML_TRUE;
|
||||
if (startDoctypeDeclHandler) {
|
||||
XML_Char *pubId;
|
||||
if (!XmlIsPublicId(enc, s, next, eventPP))
|
||||
return XML_ERROR_PUBLICID;
|
||||
doctypePubid = poolStoreString(&tempPool, enc,
|
||||
s + enc->minBytesPerChar,
|
||||
next - enc->minBytesPerChar);
|
||||
if (!doctypePubid)
|
||||
pubId = poolStoreString(&tempPool, enc,
|
||||
s + enc->minBytesPerChar,
|
||||
next - enc->minBytesPerChar);
|
||||
if (!pubId)
|
||||
return XML_ERROR_NO_MEMORY;
|
||||
normalizePublicId((XML_Char *)doctypePubid);
|
||||
normalizePublicId(pubId);
|
||||
poolFinish(&tempPool);
|
||||
doctypePubid = pubId;
|
||||
handleDefault = XML_FALSE;
|
||||
goto alreadyChecked;
|
||||
}
|
||||
@@ -3844,8 +3847,8 @@ doProlog(XML_Parser parser,
|
||||
entity->publicId))
|
||||
return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
|
||||
if (dtd->paramEntityRead) {
|
||||
if (!dtd->standalone &&
|
||||
notStandaloneHandler &&
|
||||
if (!dtd->standalone &&
|
||||
notStandaloneHandler &&
|
||||
!notStandaloneHandler(handlerArg))
|
||||
return XML_ERROR_NOT_STANDALONE;
|
||||
}
|
||||
@@ -4283,7 +4286,7 @@ doProlog(XML_Parser parser,
|
||||
switch (tok) {
|
||||
case XML_TOK_PARAM_ENTITY_REF:
|
||||
/* PE references in internal subset are
|
||||
not allowed within declarations. */
|
||||
not allowed within declarations. */
|
||||
return XML_ERROR_PARAM_ENTITY_REF;
|
||||
case XML_TOK_XML_DECL:
|
||||
return XML_ERROR_MISPLACED_XML_PI;
|
||||
@@ -4404,7 +4407,7 @@ doProlog(XML_Parser parser,
|
||||
return XML_ERROR_RECURSIVE_ENTITY_REF;
|
||||
if (entity->textPtr) {
|
||||
enum XML_Error result;
|
||||
XML_Bool betweenDecl =
|
||||
XML_Bool betweenDecl =
|
||||
(role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE);
|
||||
result = processInternalEntity(parser, entity, betweenDecl);
|
||||
if (result != XML_ERROR_NONE)
|
||||
@@ -4599,7 +4602,7 @@ doProlog(XML_Parser parser,
|
||||
reportDefault(parser, enc, s, next);
|
||||
|
||||
switch (ps_parsing) {
|
||||
case XML_SUSPENDED:
|
||||
case XML_SUSPENDED:
|
||||
*nextPtr = next;
|
||||
return XML_ERROR_NONE;
|
||||
case XML_FINISHED:
|
||||
@@ -4669,7 +4672,7 @@ epilogProcessor(XML_Parser parser,
|
||||
}
|
||||
eventPtr = s = next;
|
||||
switch (ps_parsing) {
|
||||
case XML_SUSPENDED:
|
||||
case XML_SUSPENDED:
|
||||
*nextPtr = next;
|
||||
return XML_ERROR_NONE;
|
||||
case XML_FINISHED:
|
||||
@@ -4712,12 +4715,12 @@ processInternalEntity(XML_Parser parser, ENTITY *entity,
|
||||
#ifdef XML_DTD
|
||||
if (entity->is_param) {
|
||||
int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next);
|
||||
result = doProlog(parser, internalEncoding, textStart, textEnd, tok,
|
||||
result = doProlog(parser, internalEncoding, textStart, textEnd, tok,
|
||||
next, &next, XML_FALSE);
|
||||
}
|
||||
else
|
||||
else
|
||||
#endif /* XML_DTD */
|
||||
result = doContent(parser, tagLevel, internalEncoding, textStart,
|
||||
result = doContent(parser, tagLevel, internalEncoding, textStart,
|
||||
textEnd, &next, XML_FALSE);
|
||||
|
||||
if (result == XML_ERROR_NONE) {
|
||||
@@ -4757,13 +4760,13 @@ internalEntityProcessor(XML_Parser parser,
|
||||
#ifdef XML_DTD
|
||||
if (entity->is_param) {
|
||||
int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next);
|
||||
result = doProlog(parser, internalEncoding, textStart, textEnd, tok,
|
||||
result = doProlog(parser, internalEncoding, textStart, textEnd, tok,
|
||||
next, &next, XML_FALSE);
|
||||
}
|
||||
else
|
||||
#endif /* XML_DTD */
|
||||
result = doContent(parser, openEntity->startTagLevel, internalEncoding,
|
||||
textStart, textEnd, &next, XML_FALSE);
|
||||
result = doContent(parser, openEntity->startTagLevel, internalEncoding,
|
||||
textStart, textEnd, &next, XML_FALSE);
|
||||
|
||||
if (result != XML_ERROR_NONE)
|
||||
return result;
|
||||
@@ -4784,7 +4787,7 @@ internalEntityProcessor(XML_Parser parser,
|
||||
int tok;
|
||||
processor = prologProcessor;
|
||||
tok = XmlPrologTok(encoding, s, end, &next);
|
||||
return doProlog(parser, encoding, s, end, tok, next, nextPtr,
|
||||
return doProlog(parser, encoding, s, end, tok, next, nextPtr,
|
||||
(XML_Bool)!ps_finalBuffer);
|
||||
}
|
||||
else
|
||||
@@ -4793,8 +4796,8 @@ internalEntityProcessor(XML_Parser parser,
|
||||
processor = contentProcessor;
|
||||
/* see externalEntityContentProcessor vs contentProcessor */
|
||||
return doContent(parser, parentParser ? 1 : 0, encoding, s, end,
|
||||
nextPtr, (XML_Bool)!ps_finalBuffer);
|
||||
}
|
||||
nextPtr, (XML_Bool)!ps_finalBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
static enum XML_Error PTRCALL
|
||||
@@ -4947,7 +4950,7 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
|
||||
if (!entity->textPtr) {
|
||||
if (enc == encoding)
|
||||
eventPtr = ptr;
|
||||
return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF;
|
||||
return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF;
|
||||
}
|
||||
else {
|
||||
enum XML_Error result;
|
||||
|
||||
@@ -1744,7 +1744,7 @@ PREFIX(updatePosition)(const ENCODING *enc,
|
||||
const char *end,
|
||||
POSITION *pos)
|
||||
{
|
||||
while (ptr != end) {
|
||||
while (ptr < end) {
|
||||
switch (BYTE_TYPE(enc, ptr)) {
|
||||
#define LEAD_CASE(n) \
|
||||
case BT_LEAD ## n: \
|
||||
|
||||
Reference in New Issue
Block a user