BOOL CXMLElement::Equals(CXMLElement* pXML) const { if ( this == NULL || pXML == NULL ) return FALSE; if ( pXML == this ) return TRUE; if ( m_sName != pXML->m_sName ) return FALSE; if ( m_sValue != pXML->m_sValue ) return FALSE; if ( GetAttributeCount() != pXML->GetAttributeCount() ) return FALSE; if ( GetElementCount() != pXML->GetElementCount() ) return FALSE; for ( POSITION pos = GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttribute1 = GetNextAttribute( pos ); CXMLAttribute* pAttribute2 = pXML->GetAttribute( pAttribute1->m_sName ); if ( pAttribute2 == NULL ) return FALSE; if ( ! pAttribute1->Equals( pAttribute2 ) ) return FALSE; } POSITION pos1 = GetElementIterator(); POSITION pos2 = pXML->GetElementIterator(); for ( ; pos1 && pos2 ; ) { CXMLElement* pElement1 = GetNextElement( pos1 ); CXMLElement* pElement2 = pXML->GetNextElement( pos2 ); if ( pElement1 == NULL || pElement2 == NULL ) return FALSE; if ( ! pElement1->Equals( pElement2 ) ) return FALSE; } if ( pos1 != NULL || pos2 != NULL ) return FALSE; return TRUE; }
void CXMLElement::AddRecursiveWords(CString& strWords) const { for ( POSITION pos = GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttribute = GetNextAttribute( pos ); CString strText = pAttribute->GetName(); if ( strText.Find( ':' ) >= 0 ) continue; if ( strText.CompareNoCase( _T("SHA1") ) == 0 ) continue; // NOTE: PeerProject/Shareaza Specific if ( ! strWords.IsEmpty() ) strWords += ' '; strWords += pAttribute->GetValue(); } for ( POSITION pos = GetElementIterator() ; pos ; ) { GetNextElement( pos )->AddRecursiveWords( strWords ); } if ( ! m_sValue.IsEmpty() ) { if ( ! strWords.IsEmpty() ) strWords += ' '; strWords += m_sValue; } }
CXMLElement* CXMLElement::Clone(CXMLElement* pParent) const { CXMLElement* pClone = new CXMLElement( pParent, m_sName ); if ( ! pClone ) return NULL; // Out of memory for ( POSITION pos = GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttribute = GetNextAttribute( pos )->Clone( pClone ); if ( ! pAttribute ) return NULL; // Out of memory CString strNameLower( pAttribute->m_sName ); strNameLower.MakeLower(); // Delete the old attribute if one exists CXMLAttribute* pExisting; if ( pClone->m_pAttributes.Lookup( strNameLower, pExisting ) ) delete pExisting; pClone->m_pAttributes.SetAt( strNameLower, pAttribute ); if ( ! pClone->m_pAttributesInsertion.Find( strNameLower ) ) pClone->m_pAttributesInsertion.AddTail( strNameLower ); // Track output order workaround } for ( POSITION pos = GetElementIterator() ; pos ; ) { CXMLElement* pElement = GetNextElement( pos ); pClone->m_pElements.AddTail( pElement->Clone( pClone ) ); } ASSERT( ! pClone->m_sName.IsEmpty() ); pClone->m_sValue = m_sValue; return pClone; }
// GetAllocationInfo void Node::GetAllocationInfo(AllocationInfo &info) { Attribute *attribute = NULL; while (GetNextAttribute(&attribute) == B_OK) attribute->GetAllocationInfo(info); }
void CXMLElement::Serialize(CArchive& ar) { CXMLNode::Serialize( ar ); if ( ar.IsStoring() ) { ar.WriteCount( GetAttributeCount() ); for ( POSITION pos = GetAttributeIterator() ; pos ; ) { GetNextAttribute( pos )->Serialize( ar ); } ar.WriteCount( GetElementCount() ); for ( POSITION pos = GetElementIterator() ; pos ; ) { GetNextElement( pos )->Serialize( ar ); } } else // Loading { for ( int nCount = (int)ar.ReadCount() ; nCount > 0 ; nCount-- ) { CXMLAttribute* pAttribute = new CXMLAttribute( this ); pAttribute->Serialize( ar ); // Skip attribute if name is missing if ( pAttribute->m_sName.IsEmpty() ) { delete pAttribute; continue; } CString strNameLower( pAttribute->m_sName ); strNameLower.MakeLower(); // Delete the old attribute if one exists CXMLAttribute* pExisting; if ( m_pAttributes.Lookup( strNameLower, pExisting ) ) delete pExisting; m_pAttributes.SetAt( strNameLower, pAttribute ); if ( ! m_pAttributesInsertion.Find( strNameLower ) ) m_pAttributesInsertion.AddTail( strNameLower ); // Track output order workaround } for ( int nCount = (int)ar.ReadCount() ; nCount > 0 ; nCount-- ) { CXMLElement* pElement = new CXMLElement( this ); pElement->Serialize( ar ); m_pElements.AddTail( pElement ); } } }
void XDMFParser::SkipToEndTag() { ElementType elementType; // // Read the rest of the start tag and get the next element. // while (GetNextAttribute()) /* do nothing */; elementType = GetNextElement(); // // Keep reading tags until we get a zero nesting level. // int nestingLevel = 1; while (elementType != TYPE_EOF) { switch (elementType) { case TYPE_START_TAG: nestingLevel++; // // Read the rest of the start tag. // while (GetNextAttribute()) /* do nothing */; break; case TYPE_END_TAG: nestingLevel--; break; default: break; } if (nestingLevel == 0) break; elementType = GetNextElement(); } }
void CXMLElement::ToString(CString& strXML, BOOL bNewline) const { // strXML += '<' + m_sName; Optimzed: strXML.AppendChar( _T('<') ); strXML.Append( m_sName ); POSITION pos = GetAttributeIterator(); for ( ; pos ; ) { strXML.AppendChar( _T(' ') ); const CXMLAttribute* pAttribute = GetNextAttribute( pos ); pAttribute->ToString( strXML ); } pos = GetElementIterator(); if ( pos == NULL && m_sValue.IsEmpty() ) { strXML.Append( _PT("/>") ); if ( bNewline ) strXML.Append( _PT("\r\n") ); return; } strXML.AppendChar( _T('>') ); if ( bNewline && pos ) strXML.Append( _PT("\r\n") ); while ( pos ) { const CXMLElement* pElement = GetNextElement( pos ); pElement->ToString( strXML, bNewline ); } strXML += Escape( m_sValue ); strXML.Append( _PT("</") ); strXML.Append( m_sName ); strXML.AppendChar( _T('>') ); if ( bNewline ) strXML.Append( _PT("\r\n") ); }
void XDMFParser::PrintFile() { int j; int indent = 0; // // Process the next 100000 elements. This is a precaution against // getting into an infinite loop. It could just as well be a while // true loop. // for (int i = 0; i < 100000; i++) { // // We are getting the element type at the beginning of the // loop so that we can handle the END_TAG now to get the // indentation correct. // ElementType elementType = GetNextElement(); if (elementType == TYPE_END_TAG) indent--; for (int k = 0; k < indent ; k++) cerr << " "; switch (elementType) { case TYPE_PI: cerr << "Processing Information." << endl; break; case TYPE_COMMENT: cerr << "Comment." << endl; break; case TYPE_SPECIAL: cerr << "Special." << endl; break; case TYPE_START_TAG: indent++; cerr << "<" << GetElementName(); j = 0; while (j < 100 && GetNextAttribute()) { cerr << " " << GetAttributeName() << "=\"" << GetAttributeValue() << "\""; j++; } cerr << ">" << endl; break; case TYPE_END_TAG: cerr << "</" << GetElementName() << ">" << endl; break; case TYPE_CDATA: if (GetCDataLength() <= 1023) cerr << GetCDataValue() << endl; else { FILE *file = fopen(fname, "r"); fseek(file, GetCDataOffset(), SEEK_SET); char *buf = new char[GetCDataLength()+1]; fread(buf, 1, GetCDataLength(), file); buf[GetCDataLength()] = '\0'; fclose(file); cerr << buf << endl; delete [] buf; } break; case TYPE_EOF: return; break; case TYPE_ERROR: cerr << "Error." << endl; break; } } }