Exemple #1
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);
			}
		}
	}
}
void SAX2PrintHandlers::startElement(const   XMLCh* const    uri,
                                     const   XMLCh* const    localname,
                                     const   XMLCh* const    qname,
                                     const   Attributes&		attributes)
{
    // The name has to be representable without any escapes
    fFormatter  << XMLFormatter::NoEscapes << chOpenAngle ;
    if ( fExpandNS )
    {
        if (XMLString::compareIString(uri,XMLUni::fgZeroLenString) != 0)
            fFormatter  << uri << chColon;
        fFormatter << localname ;
    }
    else
        fFormatter << qname ;

    unsigned int len = attributes.getLength();
    for (unsigned int index = 0; index < len; index++)
    {
        //
        //  Again the name has to be completely representable. But the
        //  attribute can have refs and requires the attribute style
        //  escaping.
        //
        fFormatter  << XMLFormatter::NoEscapes << chSpace ;
        if ( fExpandNS )
        {
            if (XMLString::compareIString(attributes.getURI(index),XMLUni::fgZeroLenString) != 0)
                fFormatter  << attributes.getURI(index) << chColon;
            fFormatter  << attributes.getLocalName(index) ;
        }
        else
            fFormatter  << attributes.getQName(index) ;

        fFormatter  << chEqual << chDoubleQuote
                    << XMLFormatter::AttrEscapes
                    << attributes.getValue(index)
                    << XMLFormatter::NoEscapes
                    << chDoubleQuote;
    }
    fFormatter << chCloseAngle;
}
void AttributesImpl::setAttributes(const Attributes& attributes)
{
	if (&attributes != this)
	{
		int count = attributes.getLength();
		_attributes.clear();
		_attributes.reserve(count);
		for (int i = 0; i < count; i++)
		{
			addAttribute(attributes.getURI(i), attributes.getLocalName(i), attributes.getQName(i), attributes.getType(i), attributes.getValue(i));
		}
	}
}
Exemple #4
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);
	}
}
// ---------------------------------------------------------------------------
//  SAX2SortAttributesFilter: Overrides of the SAX2XMLFilter interface
// ---------------------------------------------------------------------------
void SAX2SortAttributesFilter::startElement(const   XMLCh* const    uri,
                                            const   XMLCh* const    localname,
                                            const   XMLCh* const    qname,
                                            const   Attributes&		attributes)
{
    AttrList sortedList(attributes.getLength());
    for(XMLSize_t i=0;i<attributes.getLength();i++)
    {
        XMLSize_t j;
        for(j=0;j<sortedList.getLength();j++)
        {
            if(XMLString::compareString(sortedList.elementAt(j)->qName,attributes.getQName(i))>=0)
                break;
        }
        Attr* pClone=new Attr;
        pClone->qName       = attributes.getQName(i);
        pClone->uri         = attributes.getURI(i);
        pClone->localPart   = attributes.getLocalName(i);
        pClone->value       = attributes.getValue(i);
        pClone->attrType    = attributes.getType(i);
        sortedList.insertElementAt(pClone, j);
    }
    SAX2XMLFilterImpl::startElement(uri, localname, qname, sortedList);
}