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(); }
std::string XMLWriter::nameToString(const XMLString& localName, const XMLString& qname) { if (qname.empty()) return fromXMLString(localName); else return fromXMLString(qname); }
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; }
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); } } } }
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; } }
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; }
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); } }
void XMLWriter::writeName(const XMLString& prefix, const XMLString& localName) { if (prefix.empty()) { writeXML(localName); } else { writeXML(prefix); writeMarkup(MARKUP_COLON); writeXML(localName); } }
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; }
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(); }
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; }
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); } }
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); } }
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; } }
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; } }
static void doctypePI(xercesc::DocTypeHandler& self, const XMLString& target, const XMLString& data) { self.doctypePI(target.ptr(), data.ptr()); }
static void endElement(xercesc::DocumentHandler& self, const XMLString& name) { self.endElement(name.ptr()); }
static void doctypeWhitespace(xercesc::DocTypeHandler& self, const XMLString& chars) { self.doctypeWhitespace(chars.ptr(), chars.size()); }
void XMLWriter::writeXML(const XMLString& str) const { _pTextConverter->write((const char*) str.data(), (int) str.size()*sizeof(XMLChar)); }
static void processingInstruction(xercesc::DocumentHandler& self, const XMLString& target, const XMLString& data) { self.processingInstruction(target.ptr(), data.ptr()); }
static void ignorableWhitespace(xercesc::DocumentHandler& self, const XMLString& chars) { self.ignorableWhitespace(chars.ptr(), chars.size()); }
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); }
static void TextDecl(xercesc::DocTypeHandler& self, const XMLString& versionStr, const XMLString& encodingStr) { self.TextDecl(versionStr.ptr(), encodingStr.ptr()); }
void XMLWriter::characters(const XMLString& str) { characters(str.data(), 0, (int) str.length()); }
static void characters(xercesc::DocumentHandler& self, const XMLString& chars) { self.characters(chars.ptr(), chars.size()); }
void XMLWriter::rawCharacters(const XMLString& str) { if (_unclosedStartTag) closeStartTag(); _contentWritten = _contentWritten || !str.empty(); writeXML(str); }
bool Name::equalsWeakly(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const { return (_qname == qname && !qname.empty()) || (_namespaceURI == namespaceURI && _localName == localName && !_localName.empty()); }
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; }
static void startElement(xercesc::DocumentHandler& self, const XMLString& name, xercesc::AttributeList& attrs) { self.startElement(name.ptr(), attrs); }
static void doctypeComment(xercesc::DocTypeHandler& self, const XMLString& comment) { self.doctypeComment(comment.ptr()); }