EXPORT_C RAttribute RAttribute::Copy() /** Copy method. The original and copy must be closed seperately. */ { RAttribute copy; RTagInfo tagCopy = iAttribute.Copy(); copy.Open(const_cast <RString&> (tagCopy.Uri()), const_cast <RString&> (tagCopy.Prefix()), const_cast <RString&> (tagCopy.LocalName()), iValue.Copy(), iType); return copy; }
void CSenXmlReader::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt /* aErrorCode */) { if(!iContentHandler) { SENDEBUG_L("OnStartElementL: KErrSenXmlContentHandlerNotSet"); User::Leave(KErrSenXmlContentHandlerNotSet); } const TPtrC8 localName = aElement.LocalName().DesC(); const TPtrC8 nsUri = aElement.Uri().DesC(); const TPtrC8 prefix = aElement.Prefix().DesC(); TPtrC8 qualifiedName = localName; if (prefix != KNullDesC8) { HBufC8* pQName = HBufC8::NewLC(prefix.Length()+localName.Length()+ KSenColon().Length()); TPtr8 qName = pQName->Des(); qName.Append(prefix); qName.Append(KSenColon); qName.Append(localName); qualifiedName.Set(qName); } if(ipNsPrefixes) { // there are namespaces to declare! // make a new array for all attributes including namespace (to be added) RAttributeArray attributesAndNamespaces; CleanupClosePushL(attributesAndNamespaces); TInt nsDeclarationCount(ipNsPrefixes->Count()); for(TInt i=0; i<nsDeclarationCount; i++) { // open and take ownership of RString - xmlnsAttrPrefix RAttribute nsAttribute; //CleanupClosePushL(nsAttribute); TPtrC8 nsPrefix = ipNsPrefixes->MdcaPoint(i); TPtrC8 nsURI = ipNsUris->MdcaPoint(i); if (nsPrefix != KNullDesC8) { nsAttribute.Open(iStringPool.OpenStringL(nsURI), iStringPool.OpenStringL(KSenXmlns()), iStringPool.OpenStringL(nsPrefix), iStringPool.OpenStringL(nsURI) ); } else { nsAttribute.Open(iStringPool.OpenStringL(nsURI), iStringPool.OpenStringL(KNullDesC8()), iStringPool.OpenStringL(KSenXmlns()), iStringPool.OpenStringL(nsURI) ); } // append the namespace attribute (declaration) CleanupClosePushL(nsAttribute); attributesAndNamespaces.AppendL(nsAttribute); CleanupStack::Pop(); // nsAttribute } // the ns declarations have been done using NON-CANONIZING method delete ipNsPrefixes; ipNsPrefixes = NULL; delete ipNsUris; ipNsUris = NULL; // append all other ("real") attributes TInt count(aAttributes.Count()); for(TInt a=0; a<count; a++) { attributesAndNamespaces.AppendL(const_cast <RAttribute&> (aAttributes[a]).Copy()); } // now give the stream content forward to the interested handler object. // we have successfully added the namespace declaration as NON-canonized(!) // attribute (if conditions have been met). iContentHandler->StartElement(nsUri, localName, qualifiedName, attributesAndNamespaces); // close the copied attributes previously added into this array as copies count = attributesAndNamespaces.Count(); for(TInt j=0; j<count; j++) { attributesAndNamespaces[j].Close(); } // close the actual array CleanupStack::PopAndDestroy(); // attributesAndNamespaces.Close(); } else { // give the original attributes to content handler (no new namespaces declared in attrs) iContentHandler->StartElement(nsUri, localName, qualifiedName, aAttributes); } // delete qualified element name, if one was allocated if (prefix != KNullDesC8) { CleanupStack::PopAndDestroy(); // pQName } }