BOOL CBitziDownloader::MergeMetaData(CXMLElement* pOutput, CXMLElement* pInput) { if ( ! pOutput || ! pInput ) return FALSE; pOutput = pOutput->GetFirstElement(); if ( ! pOutput || pOutput->GetName() != pInput->GetName() ) return FALSE; for ( POSITION pos = pInput->GetElementIterator() ; pos ; ) { CXMLElement* pElement = pInput->GetNextElement( pos ); CXMLElement* pTarget = pOutput->GetElementByName( pElement->GetName() ); if ( pTarget == NULL ) pOutput->AddElement( pElement->Clone() ); } for ( POSITION pos = pInput->GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttribute = pInput->GetNextAttribute( pos ); CXMLAttribute* pTarget = pOutput->GetAttribute( pAttribute->GetName() ); if ( pTarget == NULL ) pOutput->AddAttribute( pAttribute->Clone() ); } return TRUE; }
Bool CXMLDocument::AddDTD(char *data, unsigned long tlength) { if (!isinited()) return False; xmlParserInputBufferPtr dtdInputBufferPtr; xmlDtdPtr dtd; dtdInputBufferPtr = xmlParserInputBufferCreateMem(data, tlength, XML_CHAR_ENCODING_UTF8); dtd = xmlIOParseDTD(NULL, dtdInputBufferPtr, XML_CHAR_ENCODING_UTF8); if (!dtd) return False; if (dtd->name != NULL) xmlFree((char*)dtd->name); CXMLElement telement; GetRootElement(&telement); dtd->name = xmlStrdup((xmlChar *)telement.GetName()); doc->intSubset = dtd; if (dtd->ExternalID != NULL) { xmlFree((xmlChar *) dtd->ExternalID); dtd->ExternalID = NULL; } if (dtd->SystemID != NULL) { xmlFree((xmlChar *) dtd->SystemID); dtd->SystemID = NULL; } dtd->doc = doc; dtd->parent = doc; if (doc->children == NULL) xmlAddChild((xmlNodePtr)doc, (xmlNodePtr)dtd); else xmlAddPrevSibling(doc->children, (xmlNodePtr)dtd); return Validate(); }
BOOL CSchemaMember::LoadType(const CXMLElement* pType) { CString strName = pType->GetName(); if ( strName.CompareNoCase( L"simpleType" ) && strName.CompareNoCase( L"complexType" ) ) return FALSE; m_sType = pType->GetAttributeValue( L"base", L"" ); ToLower( m_sType ); m_bNumeric = ( m_sType == L"decimal" || m_sType == L"int" || m_sType == L"short" ); m_bBoolean = m_sType == L"boolean"; m_bYear = m_sType == L"year"; m_bGUID = m_sType == L"guidtype"; for ( POSITION pos = pType->GetElementIterator(); pos; ) { CXMLElement* pElement = pType->GetNextElement( pos ); CString strElement = pElement->GetName(); if ( strElement.CompareNoCase( L"enumeration" ) == 0 ) { CString strValue = pElement->GetAttributeValue( L"value", L"" ); if ( ! strValue.IsEmpty() ) m_pItems.AddTail( strValue ); } else if ( strElement.CompareNoCase( L"maxInclusive" ) == 0 ) { CString strValue = pElement->GetAttributeValue( L"value", L"0" ); _stscanf( strValue, L"%i", &m_nMaxLength ); } } return TRUE; }
IVertexDecl * ParseVertexFormat( CXMLElement * pBranch ) { IVertexDecl * pDecl = g_pRenderer->CreateVertexDecl(); if ( !pDecl ) return NULL; uint nOffset = 0; // Перебираем все дочерние элементы ---------------------------------------- for ( size_t n = 0; n < pBranch->GetNumChilds(); ++n ) { CXMLElement * pInputElem = pBranch->GetChild( n ); CXMLAttr * pType = pInputElem->GetAttr( "Type" ); CXMLAttr * pSem = pInputElem->GetAttr( "D3D_Semantic" ); ETypeID eType = g_pSystem->GetType( pType->GetValue() ); pDecl->AddAttr( pInputElem->GetName(), ( NULL != pSem ) ? pSem->GetValue() : NULL, eType, nOffset ); nOffset += g_pSystem->GetSizeOf( eType ); } pDecl->SetStride( nOffset ); // Записывам шаг (размер) вершины в байтах return pDecl; }
BOOL CSchemaMember::LoadType(CXMLElement* pType) { CString strName = pType->GetName(); if ( strName.CompareNoCase( _T("simpleType") ) && strName.CompareNoCase( _T("complexType") ) ) return FALSE; m_sType = pType->GetAttributeValue( _T("base"), _T("") ); CharLower( m_sType.GetBuffer() ); m_sType.ReleaseBuffer(); m_bNumeric = ( m_sType == _T("short") || m_sType == _T("int") || m_sType == _T("decimal") ); for ( POSITION pos = pType->GetElementIterator() ; pos ; ) { CXMLElement* pElement = pType->GetNextElement( pos ); CString strElement = pElement->GetName(); if ( strElement.CompareNoCase( _T("enumeration") ) == 0 ) { CString strValue = pElement->GetAttributeValue( _T("value"), _T("") ); if ( strValue.GetLength() ) m_pItems.AddTail( strValue ); } else if ( strElement.CompareNoCase( _T("maxInclusive") ) == 0 ) { CString strValue = pElement->GetAttributeValue( _T("value"), _T("0") ); _stscanf( strValue, _T("%i"), &m_nMaxLength ); } } return TRUE; }
CXMLElement* CCollectionFile::CloneMetadata(CXMLElement* pMetadata) { CString strURI = pMetadata->GetAttributeValue( L"xmlns:s" ); if ( strURI.IsEmpty() ) return NULL; CXMLElement* pCore = pMetadata->GetFirstElement(); if ( pCore == NULL ) return NULL; if ( CSchemaPtr pSchema = SchemaCache.Get( strURI ) ) { pMetadata = pSchema->Instantiate(); } else { pMetadata = new CXMLElement( NULL, pCore->GetName() + 's' ); pMetadata->AddAttribute( CXMLAttribute::schemaName, strURI ); } pCore = pCore->Clone(); pMetadata->AddElement( pCore ); CString strName = pMetadata->GetName(); if ( _tcsnicmp( strName, L"s:", 2 ) == 0 ) pMetadata->SetName( strName.Mid( 2 ) ); strName = pCore->GetName(); if ( _tcsnicmp( strName, L"s:", 2 ) == 0 ) pCore->SetName( strName.Mid( 2 ) ); for ( POSITION pos = pCore->GetElementIterator(); pos; ) { CXMLNode* pNode = pCore->GetNextElement( pos ); CString strNodeName = pNode->GetName(); if ( _tcsnicmp( strNodeName, L"s:", 2 ) == 0 ) pNode->SetName( strNodeName.Mid( 2 ) ); } for ( POSITION pos = pCore->GetAttributeIterator(); pos; ) { CXMLNode* pNode = pCore->GetNextAttribute( pos ); CString strNodeName = pNode->GetName(); if ( _tcsnicmp( strNodeName, L"s:", 2 ) == 0 ) pNode->SetName( strNodeName.Mid( 2 ) ); } return pMetadata; }
/*GoChildByPath tpath - path of child element (ie. /parentelement[1]/childelement) telement - on success, navigates to element specified by tpath return True if element found */ Bool CXMLElement::GoChildByPath(char *tpath) { if (!isinited()) return False; char *sptr = tpath; char *childpointer = NULL; CXMLElement telement; telement.CopyElement(this); if (*sptr == '/') sptr++; //skip first slash Bool foundmatch = False; char *endptr = sptr + strlen(sptr); while (sptr < endptr) { char *namestart,*nameend,*nextname,*numpointer; nextname = strchr(sptr, '/' ); if (!nextname) nextname = endptr; namestart = sptr; nameend = nextname; bool t_is_text; t_is_text = (nameend == namestart) || (namestart[0] == '['); if (!telement.GoChild(NULL, t_is_text)) return False; int whichchild = 1; numpointer = util_strchr(sptr,'[',nameend-sptr); if (numpointer) { whichchild = strtol((const char *)++numpointer, NULL, 10); nameend = numpointer-1; } Bool foundmatch = False; int childcounter = 0; do { if ((!t_is_text && util_strnicmp(telement.GetName(),namestart,nameend-namestart)==0) || (t_is_text && telement.IsTextNode())) { childcounter++; if (childcounter == whichchild) { sptr = nextname+1; foundmatch = True; } } } while (!foundmatch && telement.GoNext(NULL, t_is_text)); if (!foundmatch) return False; } CopyElement(&telement); return True; }
CXMLElement* CXMLElement::Prefix(const CString& sPrefix, CXMLElement* pParent) const { CXMLElement* pCloned = Clone( pParent ); if ( pCloned ) { pCloned->SetName( sPrefix + pCloned->GetName() ); for ( POSITION pos = pCloned->GetElementIterator() ; pos ; ) { CXMLElement* pNode = pCloned->GetNextElement( pos ); pNode->SetName( sPrefix + pNode->GetName() ); } for ( POSITION pos = pCloned->GetAttributeIterator() ; pos ; ) { CXMLAttribute* pNode = pCloned->GetNextAttribute( pos ); pNode->SetName( sPrefix + pNode->GetName() ); } } return pCloned; }
int wmain() { //const TCHAR * pFileName = _T( "AttributeLoad.xml" ); const TCHAR * pFileName = _T( "ElementLoad.xml" ); //const TCHAR * pFileName = _T( "expat_test.vcproj" ); //const TCHAR * pFileName = _T( "vcproj.xml" ); CXMLDocument * pDoc = NULL; { CXMLReader clReader; pDoc = clReader.Load( pFileName ); if( pDoc == NULL ) { ::wprintf( L"Parse error at file: %s, line %lu:\n%s\n", pFileName, clReader.GetErrorLine(), clReader.GetErrorString() ); return 0; } } DumpAllXMLElement( CXMLDocument::GetElement( pDoc->GetRoot(), _T( "Root" ) ) ); { CXMLElement * pElement = CXMLDocument::GetElement( pDoc->GetRoot(), _T( "/Root/Monster" ) ); DumpAllXMLElement( pElement ); CXMLElement * pNotFound = CXMLDocument::GetElement( pDoc->GetRoot(), _T( "/Rootadf/Monster" ) ); if( pNotFound != NULL ) { wprintf( L"Found! Name: %s\n", pNotFound->GetName() ); } const TCHAR * pText = CXMLDocument::GetText( pElement, _T( "Name/" ) ); if( pText != NULL ) { wprintf( L"Name Text: %s\n", pText ); } const TCHAR * pValue = CXMLDocument::GetAttr( pElement, _T( "/Name" ), _T( "Attr" ) ); if( pValue != NULL ) { wprintf( L"Name Attr: %s\n", pValue ); } } return 0; }
/* BOOL CUserChannel::OnSyncMirrorView(CXMLElement* pXML) { CSingleLock pLock( &Traffic.m_pSection, TRUE ); for ( POSITION pos = pXML->GetElementIterator() ; pos ; ) { CXMLElement* pSync = pXML->GetNextElement( pos ); CString strValue = pSync->GetName(); if ( RTPSessionLayer* pChannel = Traffic.FindChannel(strValue) ) { CString strSSRC = pSync->GetAttributeValue( "SSRC" ); if ( pXML->GetAttribute("leave") ) pChannel->LeavedMirror( "", 0 ); else pChannel->JoinedMirror( "", _ttoi(strSSRC) ); } } return TRUE; } */ BOOL CUserChannel::OnSyncMonitorView(CXMLElement* pXML) { CWaitCursor pCursor; CSingleLock pLock( &Traffic.m_pSection, TRUE ); for ( POSITION pos = pXML->GetElementIterator() ; pos ; ) { CXMLElement* pSync = pXML->GetNextElement( pos ); CString strValue = pSync->GetName(); if ( RTPSessionLayer* pChannel = Traffic.FindChannel(strValue) ) { pChannel->JoinMirror( m_xUserId, pSync, ! pXML->GetAttribute("leave") ); } } return TRUE; }
CString CBitziDownloader::LookupValue(LPCTSTR pszPath) { CString strName, strPath( pszPath ); CXMLElement* pXML = m_pXML; BOOL bFirst = TRUE; while ( strPath.GetLength() ) { strName = strPath.SpanExcluding( _T("/") ); strPath = strPath.Mid( strName.GetLength() ); if ( strPath.IsEmpty() ) { return pXML->GetAttributeValue( strName, NULL ); } if ( bFirst ) { bFirst = FALSE; if ( strName.CompareNoCase( pXML->GetName() ) ) pXML = NULL; } else { pXML = pXML->GetElementByName( strName ); } if ( ! pXML ) { strName.Empty(); return strName; } strPath = strPath.Mid( 1 ); } strName.Empty(); if ( pXML ) strName = pXML->GetValue(); return strName; }
void CShaderCfgLoader::FinalizeRes( TResource * pRes ) { pRes->eState = TResource::FAILED; //-------------------------------------------------------------------------- // Tip: Check XMLWrapper //-------------------------------------------------------------------------- IXMLWrapper * pWrapper = (IXMLWrapper *)g_pSystem->GetInterface( IT_UTIL ); if ( !pWrapper ) return; CXMLElement * pRoot = NULL; pWrapper->LoadXMLFromMem( (char *)pRes->pBuffer, pRes->nSize, &pRoot ); DEL_ARRAY( pRes->pBuffer ); //pRes->pResource = pRoot; //-------------------------------------------------------------------------- // Tip: Check root element name //-------------------------------------------------------------------------- CStr sName( pRoot->GetName() ); if ( !sName.Compare( "Shaders" ) ) { DEL( pRoot ); return; } //-------------------------------------------------------------------------- // Tip: Parsing shaders //-------------------------------------------------------------------------- for ( size_t i = 0; i < pRoot->GetNumChilds(); ++i ) { //---------------------------------------------------------------------- // Tip: New shader //---------------------------------------------------------------------- CXMLElement * pShaderBranch = pRoot->GetChild( i ); CStr sPath( "Shaders/" ); sPath.Add( pShaderBranch->GetName() ); // const CStr sShader( pShaderBranch->GetName() ); // CBaseShader * pShader = NEW CBaseShader( sShader.GetString() ); // CXMLAttr * pProgPath = pShaderBranch->GetAttr( "ProgramPath" ); // CStr sProgPath( pProgPath->GetValue() ); SysWrite( Va( "\tshader %s", pShaderBranch->GetName() ) ); IVertexDecl * pDecl = NULL; TUniform * pUniforms = NULL; uint nUnfmCount = 0; //---------------------------------------------------------------------- // Tip: Parse shader data //---------------------------------------------------------------------- for ( size_t j = 0; j < pShaderBranch->GetNumChilds(); ++j ) { CXMLElement * pStruct = pShaderBranch->GetChild( j ); const CStr sStruct( pStruct->GetName() ); if ( sStruct.Compare( "VertexFormat" ) ) { pDecl = ParseVertexFormat( pStruct ); } else if ( sStruct.Compare( "Constants" ) ) { /* pShader->m_nUniformCount = 1; pShader->m_pUniforms = NEW CBaseShader::TUniform [ pShader->m_nUniformCount ]; pShader->m_pUniforms[ 0 ].sName = "vColorMod"; pShader->m_pUniforms[ 0 ].eType = TYPE_VEC4; pShader->m_pUniforms[ 0 ].nLoc = pShader->GetUniformLoc( pShader->m_pUniforms[ 0 ].sName ); pShader->m_pUniforms[ 0 ].nCount = 1; m_ppShaders[ UI_SHADER ] = pShader; */ nUnfmCount = ParseConstants( pStruct, &pUniforms ); //pShader->ParseMaps( pStruct ); } } g_pRenderer->CreateShader( sPath.GetString(), pDecl, pUniforms, nUnfmCount ); } DEL( pRoot ); pRes->eState = TResource::LOADED; }