1424
Конференция C SoobCha
письмо # 1426
|
1427 |
|
Привет Коллеги !!!Вопрос нежданно появился : Уже может и задавал, но забыл. Мне нужно вытягивать из файлов *.xml информацию. Как это делать - без понятия. Задвал вопрос в Progz.ru - присоветовали мало. По ихним ссылкам добрался до такого вот рабочего исходного кода: (обработку ошибок выкусил) ============================== #include <atlbase.h> #include <msxml.h> #include <iostream> void main() { // Start COM CoInitialize(NULL); // Open the file...note this simplistic executable // assumes the file is named "xmldata.xml" and is // Create an instance of the parser CComPtr<IXMLDOMDocument> spXMLDOM; HRESULT hr = spXMLDOM.CoCreateInstance(__uuidof(DOMDocument)); // Load the XML document file... VARIANT_BOOL bSuccess = false; hr = spXMLDOM->load(CComVariant(L"xmldata.xml"),&bSuccess); // Check for <xmldata> // <xmlnode>... // Construct search string // "xmldata/xmlnode" CComBSTR bstrSS(L"xmldata/xmlnode"); CComPtr<IXMLDOMNode> spXMLNode; hr = spXMLDOM->selectSingleNode(bstrSS,&spXMLNode); // The COM object "spXMLNode" now contains the XML CComPtr<IXMLDOMNode> spXMLChildNode; hr = spXMLDOM->createNode(CComVariant(NODE_ELEMENT),CComBSTR("xmlchildnode"),NULL,&spXMLChildNode); // Place the node...if all goes well, the two nodal CComPtr<IXMLDOMNode> spInsertedNode; hr = spXMLNode->appendChild(spXMLChildNode,&spInsertedNode); // Add the attribute. Note we do this through the IXMLDOMElement // interface, so we need to do the QI(). CComQIPtr<IXMLDOMElement> spXMLChildElement; spXMLChildElement = spInsertedNode; hr = spXMLChildElement->setAttribute(CComBSTR(L"xml"),CComVariant(L"fun")); // Check for <xmldata> spXMLNode = NULL; // release previous node... bstrSS = L"xmldata/xmltext"; hr = spXMLDOM->selectSingleNode(bstrSS,&spXMLNode); // Pull the enclosed text and display CComVariant varValue(VT_EMPTY); hr = spXMLNode->get_nodeTypedValue(&varValue); if ( varValue.vt == VT_BSTR ) { // Display the results...since we're not using the // wide version of the STL, we need to convert the // BSTR to ANSI text for display... USES_CONVERSION; LPTSTR lpstrMsg = W2T(varValue.bstrVal); std::cout << lpstrMsg << std::endl; } CoUninitialize(); } ============================== Скачал где-то с Rsdn.ru. Екзешник работает. Исходник не компилится. ошибок аж 44! error C2065: 'IXMLDOMDocument' : undeclared identifier error C2955: 'CComPtr' : use of class template requires template argument list see declaration of 'CComPtr' error C2133: 'spXMLDOM' : unknown size Судя по всему не хватает #include Xmldom.idl (вырыл на просторах MSDN) после добавления #include Xmldom.idl - ошибки только 2 ! Не может найти этот файл ( ???? ) Этого файла у меня нет на компе ! Как такое возможно, где его взять ? Может кто даст ? Зачем он нужен ? А При создании Винь-проекта "Диалог-базед" - ошибки те-же. С добавлением 2-го Инклюда исчезают. Что делать ? !!!!!!! помогите плиизз ! -- С уважением, Вадим SafeGuard Lagosha<Анти-МЯУ>amk.lg.ua |
1424
|
1427 |
|
|
|
|