本文整理汇总了C++中IXMLDOMDocument类的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMDocument类的具体用法?C++ IXMLDOMDocument怎么用?C++ IXMLDOMDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IXMLDOMDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DomFromCOM
// Helper function to create a DOM instance:
IXMLDOMDocument * DomFromCOM()
{
HRESULT hr;
IXMLDOMDocument *pxmldoc = NULL;
HRCALL( CoCreateInstance(__uuidof(DOMDocument40),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IXMLDOMDocument),
(void**)&pxmldoc),
"Create a new DOMDocument");
HRCALL( pxmldoc->put_async(VARIANT_FALSE),
"should never fail");
HRCALL( pxmldoc->put_validateOnParse(VARIANT_FALSE),
"should never fail");
HRCALL( pxmldoc->put_resolveExternals(VARIANT_FALSE),
"should never fail");
return pxmldoc;
clean:
if (pxmldoc)
{
pxmldoc->Release();
}
return NULL;
}
示例2: CoCreateInstance
/**
* XML 파일의 형태를 Tab을 이용해서 보기 좋게 정렬한다.
* \param szIndentFileName 정렬에 사용할 스타일 시트 파일명
* return 성공 유무
*/
bool CNtlXMLDoc::SetIndent(WCHAR* szIndentFileName)
{
IXMLDOMDocument* pXSL = NULL;
CoCreateInstance(__uuidof(DOMDocument30), NULL, CLSCTX_INPROC_SERVER, __uuidof(IXMLDOMDocument), (void**)&pXSL);
if(!pXSL)
return false;
VARIANT_BOOL vBool;
pXSL->put_async(VARIANT_FALSE);
pXSL->load((_variant_t)szIndentFileName, &vBool);
VARIANT vObject;
VariantInit(&vObject);
vObject.vt = VT_DISPATCH;
vObject.pdispVal = m_pXMLDocument;
m_pXMLDocument->transformNodeToObject(pXSL, vObject);
if(pXSL)
{
pXSL->Release();
pXSL = NULL;
}
return true;
}
示例3: CreateDomDocument
bool SettingsXML::IsXmlAllowed()
{
IXMLDOMDocument* pFile = CreateDomDocument();
if (pFile)
pFile->Release();
return (pFile != NULL);
}
示例4: getAllFiles
int DicomImageSet::parseFolder(QString folderName)
{
QStringList fileList = getAllFiles(folderName);
HRESULT hr = CoInitialize(NULL);
if (!SUCCEEDED(hr))
{
return NULL;
}
hr = S_OK;
IXMLDOMDocument *pXMLDom = NULL;
IXMLDOMElement *pRoot = NULL;
BSTR bstrXML = NULL;
VARIANT varFileName;
VariantInit(&varFileName);
QProgressDialog progress (QString("Parsing all files in %1").arg(folderName), QString("Cancel"), 0, fileList.count());
CHK_HR(CreateAndInitDOM(&pXMLDom));
// Create a processing instruction element.
CHK_HR(CreateAndAddPINode(pXMLDom, L"xml", L"version='1.0'"));
// Create the root element.
CHK_HR(CreateElement(pXMLDom, L"root", &pRoot));
// Create an attribute for the <root> element, with name "created" and value "using dom".
CHK_HR(CreateAndAddAttributeNode(pXMLDom, L"path", folderName.toStdWString().c_str(), pRoot));
// Add NEWLINE for identation before </root>.
CHK_HR(CreateAndAddTextNode(pXMLDom, L"\n", pRoot));
// add <root> to document
CHK_HR(AppendChildToParent(pRoot, pXMLDom));
progress.show();
for (int i=0; i<fileList.count(); ++i)
{
insertFileItem(pXMLDom, pRoot, folderName, fileList[i]);
progress.setValue(i);
}
CHK_HR(VariantFromString(QDir(folderName).filePath(DATASET_FILE_NAME).toStdWString().c_str(), varFileName));
CHK_HR(pXMLDom->save(varFileName));
CleanUp:
SAFE_RELEASE(pRoot);
SysFreeString(bstrXML);
VariantClear(&varFileName);
CoUninitialize();
if (FAILED(hr))
{
SAFE_RELEASE(pXMLDom);
return 0;
}
return 1;
}
示例5: createAndConfigureInterface
IXMLDOMDocument *XmlParser::_openFile(const LPWSTR file, XMLERRORDATA *error)
{
if(error)
{
error->errorCode = -1;
error->line = -1;
error->reason = NULL;
}
bool ok = false;
IXMLDOMDocument *x = createAndConfigureInterface();
if(x)
{
VARIANT_BOOL bl;
VARIANT str;
//Выделяем строку.
CWA(oleaut32, VariantInit)(&str);
str.vt = VT_BSTR;
str.bstrVal = CWA(oleaut32, SysAllocString)(file);
if(str.bstrVal != NULL)
{
//Загружаем файл.
if(x->load(str, &bl) == S_OK && bl == VARIANT_TRUE)ok = true;
//Получаем ошибку.
else if(error)
{
IXMLDOMParseError *ierror;
if(x->get_parseError(&ierror) == S_OK)
{
long l;
BSTR reason = NULL;
//Заполняем структуру.
if(ierror->get_errorCode(&l) == S_OK)error->errorCode = l;
if(ierror->get_line(&l) == S_OK)error->line = l;
if(ierror->get_reason(&reason) == S_OK)error->reason = reason;
ierror->Release();
}
}
CWA(oleaut32, VariantClear)(&str);
}
//Объект не создан, освобождаем интерфейс.
if(ok == false)
{
x->Release();
x = NULL;
}
}
return x;
}
示例6:
static IXMLDOMDocument *createAndConfigureInterface(void)
{
IXMLDOMDocument *xmlDoc = (IXMLDOMDocument *)ComLibrary::_createInterface(CLSID_DOMDocument30, IID_IXMLDOMDocument);
if(xmlDoc != NULL)
{
xmlDoc->put_async(VARIANT_FALSE);
xmlDoc->put_preserveWhiteSpace(VARIANT_FALSE);
xmlDoc->put_resolveExternals(VARIANT_FALSE);
xmlDoc->put_validateOnParse(VARIANT_TRUE);
}
return xmlDoc;
}
示例7: CoInitialize
int DicomImageSet::insertDTIFileItem(const QString &datasetFolderName, const QString &queryString, const QString &dtiFileName)
{
HRESULT hr = CoInitialize(NULL);
if (!SUCCEEDED(hr))
{
return 0;
}
QString datasetFileName = datasetFolderName+DATASET_FILE_NAME;
IXMLDOMDocument *pXMLDom = NULL;
IXMLDOMElement *pNode = NULL, *pParent = NULL;
BSTR bstrQuery = NULL;
VARIANT varFileName;
VARIANT_BOOL varStatus;
QString queryDTIFile;
CHK_HR(CreateAndInitDOM(&pXMLDom));
CHK_HR(VariantFromString(datasetFileName.toStdWString().c_str(), varFileName));
CHK_HR(pXMLDom->load(varFileName, &varStatus));
/*queryDTIFile = queryString+QString("/DTI[@file_name = '%1']").arg(dtiFileName);
bstrQuery = SysAllocString(queryString.toStdWString().c_str());
CHK_ALLOC(bstrQuery);
CHK_HR(pXMLDom->selectSingleNode(bstrQuery, (IXMLDOMNode**)&pNode));
SysFreeString(bstrQuery);
if (pNode)
{
return 1;
}*/
bstrQuery = SysAllocString(queryString.toStdWString().c_str());
CHK_ALLOC(bstrQuery);
CHK_HR(pXMLDom->selectSingleNode(bstrQuery, (IXMLDOMNode**)&pParent));
SysFreeString(bstrQuery);
if (pParent)
{
CHK_HR(CreateElement(pXMLDom, L"DTI", &pNode));
CHK_HR(CreateAndAddAttributeNode(pXMLDom, L"file_name", dtiFileName.toStdWString().c_str(), pNode));
CHK_HR(CreateAndAddTextNode(pXMLDom, L"\n", pParent));
CHK_HR(AppendChildToParent(pNode, pParent));
CHK_HR(pXMLDom->save(varFileName));
return 1;
}
CleanUp:
SAFE_RELEASE(pXMLDom);
SAFE_RELEASE(pNode);
return 0;
}
示例8: CGT_CXMLEdp
CGT_CXMLEdp(IXMLDOMNode* pNode)
{
IXMLDOMDocument* pdoc;
BSTR bstr;
pNode->get_ownerDocument(&pdoc);
pdoc->get_url(&bstr);
xmlFile.load(bstr);
FC_RELEASE_PTR(pdoc);
FC_FREESYSTRING(bstr);
xmlFile.stripBeginI(_T("file:"));
while(xmlFile.stripBeginI("/"))
;
CG_InitSTEdipos(&m_edp, xmlFile, 1);//TODO impossible to get (line,col), use line 1...??
}
示例9: getOrderedDcmFiles
QStringList DicomImageSet::getOrderedDcmFiles(const QString &datasetFileName, const QString & queryString)
{
HRESULT hr = S_OK;
IXMLDOMDocument *pXMLDom = NULL;
IXMLDOMNodeList *pFileNodes = NULL;
VARIANT_BOOL varStatus;
VARIANT varFileName;
BSTR bstrQuery;
QStringList fileList;
CHK_HR(CreateAndInitDOM(&pXMLDom));
CHK_HR(VariantFromString(datasetFileName.toStdWString().c_str(), varFileName));
CHK_HR(pXMLDom->load(varFileName, &varStatus));
if (varStatus != VARIANT_TRUE)
{
CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
}
bstrQuery = SysAllocString(queryString.toStdWString().c_str());
CHK_ALLOC(bstrQuery);
CHK_HR(pXMLDom->selectNodes(bstrQuery, &pFileNodes));
if (pFileNodes)
{
long nFiles;
CHK_HR(pFileNodes->get_length(&nFiles));
for (long i=0; i<nFiles; ++i)
{
VARIANT varValue;
IXMLDOMNode * pFile = NULL;
CHK_HR(pFileNodes->get_item(i, &pFile));
CHK_HR(GetAttributeFromNode(pFile, L"path", &varValue));
fileList <<QString::fromWCharArray(_bstr_t(varValue));
SAFE_RELEASE(pFile);
}
}
CleanUp:
SAFE_RELEASE(pXMLDom);
SAFE_RELEASE(pFileNodes);
return fileList;
}
示例10: do_CheckXML
int do_CheckXML(lua_State* L)
{
CString strXml = luaL_checkstring(L,1);
HRESULT hr;
IXMLDOMDocument * pXMLDoc;
//...
hr = CoInitialize(NULL);
// Check the return value, hr...
hr = CoCreateInstance(CLSID_DOMDocument30, NULL, CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument, (void**)&pXMLDoc);
// Check the return value, hr...
VARIANT_BOOL bSuccessful;
pXMLDoc->loadXML(strXml.AllocSysString(),&bSuccessful);
int irez = 0;
if(!bSuccessful)
{
IXMLDOMParseError *pIParseError = NULL;
pXMLDoc->get_parseError(&pIParseError);
long lineNum;
pIParseError->get_line(&lineNum);
long linePos;
pIParseError->get_linepos(&linePos);
BSTR reason;
pIParseError->get_reason(&reason);
lua_pushinteger(L, lineNum);
lua_pushinteger(L, linePos);
lua_pushstring(L, CString(reason));
pIParseError->Release();
pIParseError = NULL;
irez = 3;
}
pXMLDoc->Release();
return irez;
}
示例11: XMLLoadFile
static IXMLDOMNode* XMLLoadFile(const TCHAR* pszFile)
{
HRESULT hr;
IXMLDOMElement* pRoot;
IXMLDOMDocument* pXMLDoc;
hr = CoCreateInstance(CLSID_DOMDocument,
NULL,
CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument,
(void**)&pXMLDoc);
if(FAILED(hr))
return NULL;
_variant_t vSrc(pszFile);
VARIANT_BOOL vBool = VARIANT_FALSE;
hr = pXMLDoc->load(vSrc, &vBool);
if(FAILED(hr))
{
FC_RELEASE_PTR(pXMLDoc);
return NULL;
}
if(vBool!=VARIANT_TRUE)
{
FC_RELEASE_PTR(pXMLDoc);
return NULL;
}
pRoot = NULL;
hr = pXMLDoc->get_documentElement(&pRoot);
FC_RELEASE_PTR(pXMLDoc);
if(FAILED(hr) || !pRoot)
return NULL;
return pRoot;
}
示例12: getDTIFileName
QString DicomImageSet::getDTIFileName(const QString &datasetFolderName, const QString &queryString)
{
QString datasetFileName = datasetFolderName+DATASET_FILE_NAME;
HRESULT hr = S_OK;
IXMLDOMDocument *pXMLDom = NULL;
IXMLDOMNode *pFileNode = NULL;
VARIANT_BOOL varStatus;
VARIANT varFileName;
BSTR bstrQuery;
QStringList fileList;
CHK_HR(CreateAndInitDOM(&pXMLDom));
CHK_HR(VariantFromString(datasetFileName.toStdWString().c_str(), varFileName));
CHK_HR(pXMLDom->load(varFileName, &varStatus));
if (varStatus != VARIANT_TRUE)
{
CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
}
bstrQuery = SysAllocString(QString(queryString+"/DTI").toStdWString().c_str());
CHK_ALLOC(bstrQuery);
CHK_HR(pXMLDom->selectSingleNode(bstrQuery, &pFileNode));
if (pFileNode)
{
VARIANT varValue;
CHK_HR(GetAttributeFromNode(pFileNode, L"file_name", &varValue));
return QString::fromWCharArray(_bstr_t(varValue));
}
CleanUp:
SAFE_RELEASE(pXMLDom);
SAFE_RELEASE(pFileNode);
return QString();
}
示例13: XmlLoadDocumentEx
/********************************************************************
XmlLoadDocumentEx -
*********************************************************************/
extern "C" HRESULT DAPI XmlLoadDocumentEx(
__in_z LPCWSTR wzDocument,
__in DWORD dwAttributes,
__out IXMLDOMDocument** ppixdDocument
)
{
HRESULT hr = S_OK;
VARIANT_BOOL vbSuccess = 0;
// RELEASEME
IXMLDOMDocument* pixd = NULL;
IXMLDOMParseError* pixpe = NULL;
BSTR bstrLoad = NULL;
if (!wzDocument || !*wzDocument)
{
hr = E_UNEXPECTED;
ExitOnFailure(hr, "string must be non-null");
}
hr = XmlCreateDocument(NULL, &pixd);
if (hr == S_FALSE)
{
hr = E_FAIL;
}
ExitOnFailure(hr, "failed XmlCreateDocument");
if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE)
{
hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE);
ExitOnFailure(hr, "failed put_preserveWhiteSpace");
}
// Security issue. Avoid triggering anything external.
hr = pixd->put_validateOnParse(VARIANT_FALSE);
ExitOnFailure(hr, "failed put_validateOnParse");
hr = pixd->put_resolveExternals(VARIANT_FALSE);
ExitOnFailure(hr, "failed put_resolveExternals");
bstrLoad = ::SysAllocString(wzDocument);
ExitOnNull(bstrLoad, hr, E_OUTOFMEMORY, "failed to allocate bstr for Load in XmlLoadDocumentEx");
hr = pixd->loadXML(bstrLoad, &vbSuccess);
if (S_FALSE == hr)
{
hr = HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
}
if (FAILED(hr) && S_OK == pixd->get_parseError(&pixpe))
{
XmlReportParseError(pixpe);
}
ExitOnFailure(hr, "failed loadXML");
hr = S_OK;
LExit:
if (ppixdDocument)
{
*ppixdDocument = pixd;
pixd = NULL;
}
ReleaseBSTR(bstrLoad);
ReleaseObject(pixd);
ReleaseObject(pixpe);
return hr;
}
示例14: XmlLoadDocumentFromFileEx
/*******************************************************************
XmlLoadDocumentFromFileEx
********************************************************************/
extern "C" HRESULT DAPI XmlLoadDocumentFromFileEx(
__in_z LPCWSTR wzPath,
__in DWORD dwAttributes,
__out IXMLDOMDocument** ppixdDocument
)
{
HRESULT hr = S_OK;
VARIANT varPath;
VARIANT_BOOL vbSuccess = 0;
IXMLDOMDocument* pixd = NULL;
IXMLDOMParseError* pixpe = NULL;
::VariantInit(&varPath);
varPath.vt = VT_BSTR;
varPath.bstrVal = ::SysAllocString(wzPath);
ExitOnNull(varPath.bstrVal, hr, E_OUTOFMEMORY, "failed to allocate bstr for Path in XmlLoadDocumentFromFileEx");
hr = XmlCreateDocument(NULL, &pixd);
if (hr == S_FALSE)
{
hr = E_FAIL;
}
ExitOnFailure(hr, "failed XmlCreateDocument");
if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE)
{
hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE);
ExitOnFailure(hr, "failed put_preserveWhiteSpace");
}
// Avoid triggering anything external.
hr = pixd->put_validateOnParse(VARIANT_FALSE);
ExitOnFailure(hr, "failed put_validateOnParse");
hr = pixd->put_resolveExternals(VARIANT_FALSE);
ExitOnFailure(hr, "failed put_resolveExternals");
pixd->put_async(VARIANT_FALSE);
hr = pixd->load(varPath, &vbSuccess);
if (S_FALSE == hr)
{
hr = HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
}
if (FAILED(hr) && S_OK == pixd->get_parseError(&pixpe))
{
XmlReportParseError(pixpe);
}
ExitOnFailure1(hr, "failed to load XML from: %ls", wzPath);
if (ppixdDocument)
{
*ppixdDocument = pixd;
pixd = NULL;
}
hr = S_OK;
LExit:
ReleaseVariant(varPath);
ReleaseObject(pixd);
ReleaseObject(pixpe);
return hr;
}
示例15: readDatasetFile
int DicomImageSet::readDatasetFile(const QString &datasetFileName, QTreeWidget *treeWidget)
{
HRESULT hr = S_OK;
IXMLDOMDocument *pXMLDom = NULL;
IXMLDOMNodeList *pPatients = NULL;
IXMLDOMNode *pPatient = NULL;
DOMNodeType nodeType;
VARIANT_BOOL varStatus;
VARIANT varFileName;
VARIANT varValue;
BSTR bstrQuery;
VariantInit(&varFileName);
VariantInit(&varValue);
QString queryPatient, queryDate, queryProtocol, queryCollection;
CHK_HR(CreateAndInitDOM(&pXMLDom));
CHK_HR(VariantFromString(datasetFileName.toStdWString().c_str(), varFileName));
CHK_HR(pXMLDom->load(varFileName, &varStatus));
if (varStatus != VARIANT_TRUE)
{
CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
}
treeWidget->clear();
treeWidget->setColumnCount(1);
CHK_HR(pXMLDom->getElementsByTagName(L"Patient", &pPatients));
if (pPatients)
{
long nPatients;
CHK_HR(pPatients->get_length(&nPatients));
for (long i=0; i<nPatients; ++i)
{
CHK_HR(pPatients->get_item(i, &pPatient));
CHK_HR(GetAttributeFromNode(pPatient, L"patients_name", &varValue));
queryPatient = QString::fromWCharArray(_bstr_t(varValue));
QTreeWidgetItem * patientItem = new QTreeWidgetItem(treeWidget, QStringList(queryPatient));
patientItem->setExpanded(true);
IXMLDOMNodeList * pDates = NULL;
CHK_HR(pPatient->get_childNodes(&pDates));
long nDates;
CHK_HR(pDates->get_length(&nDates));
for (long j=0; j<nDates; ++j)
{
IXMLDOMNode * pDate = NULL;
CHK_HR(pDates->get_item(j, &pDate));
CHK_HR(pDate->get_nodeType(&nodeType));
if(nodeType!=NODE_ELEMENT)
{
continue;
}
CHK_HR(GetAttributeFromNode(pDate, L"acquisition_date", &varValue));
queryDate = QString::fromWCharArray(_bstr_t(varValue));
int intDate = queryDate.toInt();
QDate date = (QDate::fromString("1900-01-01", "yyyy-MM-dd")).addDays(intDate-693962);
QTreeWidgetItem * dateItem = new QTreeWidgetItem(patientItem, QStringList(date.toString("yyyy-MM-dd")));
dateItem->setExpanded(true);
IXMLDOMNodeList * pProtocols = NULL;
CHK_HR(pDate->get_childNodes(&pProtocols));
long nProtocols;
CHK_HR(pProtocols->get_length(&nProtocols));
for (long j=0; j<nProtocols; ++j)
{
IXMLDOMNode * pProtocol = NULL;
CHK_HR(pProtocols->get_item(j, &pProtocol));
CHK_HR(pProtocol->get_nodeType(&nodeType));
if(nodeType!=NODE_ELEMENT)
{
continue;
}
CHK_HR(GetAttributeFromNode(pProtocol, L"protocol_name", &varValue));
queryProtocol = QString::fromWCharArray(_bstr_t(varValue));
QTreeWidgetItem * protocolItem = new QTreeWidgetItem(dateItem, QStringList(queryProtocol));
protocolItem->setExpanded(true);
IXMLDOMNodeList * pCollections = NULL;
CHK_HR(pProtocol->get_childNodes(&pCollections));
long nCollections;
CHK_HR(pCollections->get_length(&nCollections));
for (long j=0; j<nCollections; ++j)
{
IXMLDOMNode * pCollection = NULL;
CHK_HR(pCollections->get_item(j, &pCollection));
CHK_HR(pCollection->get_nodeType(&nodeType));
if(nodeType!=NODE_ELEMENT)
{
continue;
}
CHK_HR(GetAttributeFromNode(pCollection, L"acquisition_number", &varValue));
queryCollection = QString::fromWCharArray(_bstr_t(varValue));
QTreeWidgetItem * collectionItem = new QTreeWidgetItem(protocolItem);
QString queryStr = QString("root/Patient[@patients_name = '%1']/Date[@acquisition_date = '%2']/Protocol[@protocol_name = '%3']/Collection[@acquisition_number = '%4']")
.arg(queryPatient).arg(queryDate).arg(queryProtocol).arg(queryCollection);
IXMLDOMElement * pDtiNode = NULL;
bstrQuery = SysAllocString(QString(queryStr+"/DTI").toStdWString().c_str());
//.........这里部分代码省略.........