Ejemplo n.º 1
0
void XMLWriter::writeEndElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname)
{
	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);
		}
		else
		{
			writeXML(qname);
		}
		writeMarkup(MARKUP_GT);
	}
	_namespaces.popContext();
}
Ejemplo n.º 2
0
std::string XMLWriter::nameToString(const XMLString& localName, const XMLString& qname)
{
	if (qname.empty())
		return fromXMLString(localName);
	else
		return fromXMLString(qname);
}
Ejemplo n.º 3
0
XMLString Name::prefix(const XMLString& qname)
{
	XMLString::size_type pos = qname.find(':');
	if (pos != XMLString::npos)
		return XMLString(qname, 0, pos);
	else
		return EMPTY_NAME;
}
Ejemplo n.º 4
0
void XMLWriter::declareAttributeNamespaces(const Attributes& attributes)
{
	for (int i = 0; i < attributes.getLength(); i++)
	{
		XMLString namespaceURI = attributes.getURI(i);
		XMLString localName    = attributes.getLocalName(i);
		XMLString qname        = attributes.getQName(i);
		if (!localName.empty())
		{
			XMLString prefix;
			XMLString splitLocalName;
			Name::split(qname, prefix, splitLocalName);
			if (prefix.empty()) prefix = _namespaces.getPrefix(namespaceURI);
			if (prefix.empty() && !namespaceURI.empty() && !_namespaces.isMapped(namespaceURI))
			{
				prefix = newPrefix();
				_namespaces.declarePrefix(prefix, namespaceURI);
			}

			const XMLString& uri = _namespaces.getURI(prefix);
			if ((uri.empty() || uri != namespaceURI) && !namespaceURI.empty())
			{
				_namespaces.declarePrefix(prefix, namespaceURI);
			}
		}
	}
}
Ejemplo n.º 5
0
void XMLWriter::addNamespaceAttributes(AttributeMap& attributeMap)
{
	NamespaceSupport::PrefixSet prefixes;
	_namespaces.getDeclaredPrefixes(prefixes);
	for (NamespaceSupport::PrefixSet::const_iterator it = prefixes.begin(); it != prefixes.end(); ++it)
	{
		XMLString prefix = *it;
		XMLString uri    = _namespaces.getURI(prefix);
		XMLString qname  = NamespaceSupport::XMLNS_NAMESPACE_PREFIX;
		
		if (!prefix.empty())
		{
			qname.append(toXMLString(MARKUP_COLON));
			qname.append(prefix);
		}
		attributeMap[qname] = uri;
	}
}
Ejemplo n.º 6
0
void XMLWriter::startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId)
{
	writeMarkup("<!DOCTYPE ");
	writeXML(name);
	if (!publicId.empty())
	{
		writeMarkup(" PUBLIC \"");
		writeXML(publicId);
		writeMarkup("\"");
	}
	if (!systemId.empty())
	{
		writeMarkup(" SYSTEM \"");
		writeXML(systemId);
		writeMarkup("\"");
	}
	_inDTD = true;
}
Ejemplo n.º 7
0
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)
{
	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())
	{
		emptyElement(namespaceURI, localName, qname, attributes);
	}
	else
	{
		startElement(namespaceURI, localName, qname, attributes);
		characters(data);
		endElement(namespaceURI, localName, qname);
	}
}
Ejemplo n.º 8
0
void XMLWriter::writeName(const XMLString& prefix, const XMLString& localName)
{
	if (prefix.empty())
	{
		writeXML(localName);
	}
	else
	{
		writeXML(prefix); 
		writeMarkup(MARKUP_COLON); 
		writeXML(localName);
	}
}
Ejemplo n.º 9
0
void DOMBuilder::startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes)
{
	AutoPtr<Element> pElem = _namespaces ? _pDocument->createElementNS(uri, qname.empty() ? localName : qname) : _pDocument->createElement(qname);

	const AttributesImpl& attrs = dynamic_cast<const AttributesImpl&>(attributes);
	Attr* pPrevAttr = 0;
	for (AttributesImpl::iterator it = attrs.begin(); it != attrs.end(); ++it)
	{
		AutoPtr<Attr> pAttr = new Attr(_pDocument, 0, it->namespaceURI, it->localName, it->qname, it->value, it->specified);
		pPrevAttr = pElem->addAttributeNodeNP(pPrevAttr, pAttr);
	}
	appendNode(pElem);
	_pParent = pElem;
}
Ejemplo n.º 10
0
void XMLWriter::processingInstruction(const XMLString& target, const XMLString& data)
{
	if (_unclosedStartTag) closeStartTag();
	prettyPrint();
	writeMarkup("<?");
	writeXML(target);
	if (!data.empty())
	{
		writeMarkup(MARKUP_SPACE);
		writeXML(data);
	}
	writeMarkup("?>");
	if (_depth == 0)
		writeNewLine();
}
Ejemplo n.º 11
0
unsigned long NamePool::hash(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName)
{
	unsigned long h = 0;
	XMLString::const_iterator it  = qname.begin();
	XMLString::const_iterator end = qname.end();
	while (it != end) h = (h << 5) + h + (unsigned long) *it++;
	it =  namespaceURI.begin();
	end = namespaceURI.end();
	while (it != end) h = (h << 5) + h + (unsigned long) *it++;
	it  = localName.begin();
	end = localName.end();
	while (it != end) h = (h << 5) + h + (unsigned long) *it++;
	return h;
}
Ejemplo n.º 12
0
void Name::split(const XMLString& qname, XMLString& prefix, XMLString& localName)
{
	XMLString::size_type pos = qname.find(':');
	if (pos != XMLString::npos)
	{
		prefix.assign(qname, 0, pos);
		localName.assign(qname, pos + 1, qname.size() - pos - 1);
	}
	else
	{
		prefix.clear();
		localName.assign(qname);
	}
}
Ejemplo n.º 13
0
void XMLWriter::addAttributes(AttributeMap& attributeMap, const Attributes& attributes, const XMLString& elementNamespaceURI)
{
	for (int i = 0; i < attributes.getLength(); i++)
	{
		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())
			{
				qname = prefix;
				qname.append(toXMLString(MARKUP_COLON));
			}
			else qname.clear();
			qname.append(localName);
		}
		attributeMap[qname] = attributes.getValue(i);
	}
}
Ejemplo n.º 14
0
void currencyHandler::endElement(const XMLString& uri,
		const XMLString& localName, const XMLString& qname) {
	//where("endElement");
	//std::cout<<"localName is "<<localName<<"  allCurrencies size is "<<allCurrencies.size()<<std::endl;

	if (localName.compare("resource") == 0) {
		std::cout << " Quote ending  here.." << std::endl;
		inQuote = false;

		currency c = *currentReadingCurrency;
		allCurrencies.push_back(c);
		/*****************/
		//we can totally ignore comment these lines
		//	delete currentReadingCurrency;
		//		currentReadingCurrency = new currency();
		/***********************/
		std::cout << " currentReadingCurrency.toString() is "
				<< currentReadingCurrency->toString() << std::endl;
		std::cout << " c.toString() is " << c.toString() << std::endl;

	}

}
Ejemplo n.º 15
0
int CSAX2ParserBase::HandleExternalEntityRef(const XML_Char* context, const XML_Char* base,
									         const XML_Char* systemId, const XML_Char* publicId)
{
	csl_assert (systemId != NULL);

	if (context == NULL && !m_includeExtParEntities) return 0;
	if (context != NULL && !m_includeExtGenEntities) return 0;

	CInputSource* pInputSource = NULL;
	XMLString resolvedSystemId;
	if (base)
		resolvedSystemId = ResolveSystemId(base, systemId);
	else
		resolvedSystemId = systemId;

	CEntityResolver* pEntityResolver = NULL;
	CEntityResolverImp defaultResolver;

	XMLString pId;
	if (publicId) pId = XMLString(publicId);

	if (m_pEntityResolver)
	{
		pInputSource = m_pEntityResolver->ResolveEntity(publicId ? &pId : NULL, resolvedSystemId);
		pEntityResolver = m_pEntityResolver;
	}
	if (!pInputSource && m_includeExtGenEntities)
	{
		pInputSource = defaultResolver.ResolveEntity(publicId ? &pId : NULL, resolvedSystemId);
		pEntityResolver = &defaultResolver;
	}

	if (pInputSource)
	{
		XML_Parser extParser = XML_ExternalEntityParserCreate(GetExpatParser(), context, 0);

		XML_SetBase(extParser, resolvedSystemId.c_str());

		try
		{
			if (pInputSource->GetCharacterStream())
			{
				ParseCharExternal(extParser, pInputSource->GetCharacterStream());
			}
			else if (pInputSource->GetByteStream())
			{
				ParseExternal(extParser, pInputSource->GetByteStream());
			}
			else
			{
				throw CSAXParseException("no input stream", EMPTY_STRING, pInputSource->GetSystemId(), 0, 0, CXMLException(CXMLException::EXMLBadInputSource, string()));
			}
		}
		catch (CXMLException& e)
		{
			// cleanup before we propagate the exception
			pEntityResolver->DoneWithInputSource(pInputSource);
			XML_ParserFree(extParser);
			throw e;
		}
		pEntityResolver->DoneWithInputSource(pInputSource);
		XML_ParserFree(extParser);
		return 1;
	}
	else
	{
		return 0;
	}
}
Ejemplo n.º 16
0
static void doctypePI(xercesc::DocTypeHandler& self, const XMLString& target, const XMLString& data) {
	self.doctypePI(target.ptr(), data.ptr());
}
Ejemplo n.º 17
0
static void endElement(xercesc::DocumentHandler& self, const XMLString& name) {
	self.endElement(name.ptr());
}
Ejemplo n.º 18
0
static void doctypeWhitespace(xercesc::DocTypeHandler& self, const XMLString& chars) {
	self.doctypeWhitespace(chars.ptr(), chars.size());
}
Ejemplo n.º 19
0
void XMLWriter::writeXML(const XMLString& str) const
{
	_pTextConverter->write((const char*) str.data(), (int) str.size()*sizeof(XMLChar));
}
Ejemplo n.º 20
0
static void processingInstruction(xercesc::DocumentHandler& self, const XMLString& target, const XMLString& data) {
	self.processingInstruction(target.ptr(), data.ptr());
}
Ejemplo n.º 21
0
static void ignorableWhitespace(xercesc::DocumentHandler& self, const XMLString& chars) {
	self.ignorableWhitespace(chars.ptr(), chars.size());
}
Ejemplo n.º 22
0
static void doctypeDecl(xercesc::DocTypeHandler& self, const xercesc::DTDElementDecl& elemDecl, const XMLString& publicId, const XMLString& systemId, const bool hasIntSubset, const bool hasExtSubset) {
	self.doctypeDecl(elemDecl, publicId.ptr(), systemId.ptr(), hasIntSubset, hasExtSubset);
}
Ejemplo n.º 23
0
static void TextDecl(xercesc::DocTypeHandler& self, const XMLString& versionStr, const XMLString& encodingStr) {
	self.TextDecl(versionStr.ptr(), encodingStr.ptr());
}
Ejemplo n.º 24
0
void XMLWriter::characters(const XMLString& str)
{
	characters(str.data(), 0, (int) str.length());
}
Ejemplo n.º 25
0
static void characters(xercesc::DocumentHandler& self, const XMLString& chars) {
	self.characters(chars.ptr(), chars.size());
}
Ejemplo n.º 26
0
void XMLWriter::rawCharacters(const XMLString& str)
{
	if (_unclosedStartTag) closeStartTag();
	_contentWritten = _contentWritten || !str.empty();
	writeXML(str);
}
Ejemplo n.º 27
0
bool Name::equalsWeakly(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const
{
	return (_qname == qname && !qname.empty()) || (_namespaceURI == namespaceURI && _localName == localName && !_localName.empty());
}
Ejemplo n.º 28
0
void XMLWriter::writeStartElement(const XMLString& namespaceURI, const XMLString& localName, const XMLString& qname, const Attributes& attributes)
{
	if (!_nsContextPushed)
		_namespaces.pushContext();
	_nsContextPushed = false;
	++_elementCount;
	writeMarkup(MARKUP_LT);
	if (!localName.empty() && (qname.empty() || localName == qname))
	{
		XMLString prefix;
		if (!namespaceURI.empty() && !_namespaces.isMapped(namespaceURI))
		{
			prefix = newPrefix();
			_namespaces.declarePrefix(prefix, namespaceURI);
		}
		else prefix = _namespaces.getPrefix(namespaceURI);
		writeName(prefix, localName);
	}
	else if (namespaceURI.empty() && localName.empty() && !qname.empty())
	{
		writeXML(qname);
	}
	else if (!localName.empty() && !qname.empty())
	{
		XMLString local;
		XMLString prefix;
		Name::split(qname, prefix, local);
		if (prefix.empty()) prefix = _namespaces.getPrefix(namespaceURI);
		const XMLString& uri = _namespaces.getURI(prefix);
		if ((uri.empty() || uri != namespaceURI) && !namespaceURI.empty())
		{
			_namespaces.declarePrefix(prefix, namespaceURI);
		}
		writeName(prefix, localName);
	}
	else throw XMLException("Tag mismatch", nameToString(localName, qname));

	declareAttributeNamespaces(attributes);
	AttributeMap attributeMap;
	addNamespaceAttributes(attributeMap);
	addAttributes(attributeMap, attributes, namespaceURI);
	writeAttributes(attributeMap);
	_unclosedStartTag = true;
}
Ejemplo n.º 29
0
static void startElement(xercesc::DocumentHandler& self, const XMLString& name, xercesc::AttributeList& attrs) {
	self.startElement(name.ptr(), attrs);
}
Ejemplo n.º 30
0
static void doctypeComment(xercesc::DocTypeHandler& self, const XMLString& comment) {
	self.doctypeComment(comment.ptr());
}