本文整理汇总了C++中IXMLDOMDocument::selectSingleNode方法的典型用法代码示例。如果您正苦于以下问题:C++ IXMLDOMDocument::selectSingleNode方法的具体用法?C++ IXMLDOMDocument::selectSingleNode怎么用?C++ IXMLDOMDocument::selectSingleNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IXMLDOMDocument
的用法示例。
在下文中一共展示了IXMLDOMDocument::selectSingleNode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertDTIFileItem
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;
}
示例2: 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();
}
示例3: SetShadersGLSL
bool COpenGL::SetShadersGLSL(const TCHAR *glslFileName)
{
char *fragment=NULL, *vertex=NULL;
IXMLDOMDocument * pXMLDoc = NULL;
IXMLDOMElement * pXDE = NULL;
IXMLDOMNode * pXDN = NULL;
HRESULT hr;
BSTR queryString, nodeContent;
TCHAR errorMsg[MAX_PATH + 50];
if(fragmentShader) {
glDetachShader(shaderProgram,fragmentShader);
glDeleteShader(fragmentShader);
fragmentShader = 0;
}
if(vertexShader) {
glDetachShader(shaderProgram,vertexShader);
glDeleteShader(vertexShader);
vertexShader = 0;
}
if(shaderProgram) {
glUseProgram(0);
glDeleteProgram(shaderProgram);
shaderProgram = 0;
}
if(glslFileName==NULL || *glslFileName==TEXT('\0'))
return true;
if(!LoadShaderFunctions()) {
MessageBox(NULL, TEXT("Unable to load OpenGL shader functions"), TEXT("Shader Loading Error"),
MB_OK|MB_ICONEXCLAMATION);
return false;
}
hr = CoCreateInstance(CLSID_DOMDocument,NULL,CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&pXMLDoc));
if(FAILED(hr)) {
MessageBox(NULL, TEXT("Error creating XML Parser"), TEXT("Shader Loading Error"),
MB_OK|MB_ICONEXCLAMATION);
return false;
}
VARIANT fileName;
VARIANT_BOOL ret;
fileName.vt = VT_BSTR;
#ifdef UNICODE
fileName.bstrVal = SysAllocString(glslFileName);
#else
wchar_t tempfilename[MAX_PATH];
MultiByteToWideChar(CP_UTF8,0,glslFileName,-1,tempfilename,MAX_PATH);
fileName.bstrVal = SysAllocString(tempfilename);
#endif
hr = pXMLDoc->load(fileName,&ret);
SysFreeString(fileName.bstrVal);
if(FAILED(hr) || hr==S_FALSE) {
_stprintf(errorMsg,TEXT("Error loading GLSL shader file:\n%s"),glslFileName);
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION);
pXMLDoc->Release();
return false;
}
VARIANT attributeValue;
BSTR attributeName;
hr = pXMLDoc->get_documentElement(&pXDE);
if(FAILED(hr) || hr==S_FALSE) {
_stprintf(errorMsg,TEXT("Error loading root element from file:\n%s"),glslFileName);
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION);
pXMLDoc->Release();
return false;
}
attributeName=SysAllocString(L"language");
pXDE->getAttribute(attributeName,&attributeValue);
SysFreeString(attributeName);
pXDE->Release();
if(attributeValue.vt!=VT_BSTR || lstrcmpiW(attributeValue.bstrVal,L"glsl")) {
_stprintf(errorMsg,TEXT("Shader language is <%s>, expected <GLSL> in file:\n%s"),attributeValue.bstrVal,glslFileName);
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION);
if(attributeValue.vt==VT_BSTR) SysFreeString(attributeValue.bstrVal);
pXMLDoc->Release();
return false;
}
if(attributeValue.vt==VT_BSTR) SysFreeString(attributeValue.bstrVal);
queryString=SysAllocString(L"/shader/fragment");
hr = pXMLDoc->selectSingleNode(queryString,&pXDN);
SysFreeString(queryString);
if(hr == S_OK) {
hr = pXDN->get_text(&nodeContent);
if(hr == S_OK) {
int requiredChars = WideCharToMultiByte(CP_ACP,0,nodeContent,-1,fragment,0,NULL,NULL);
fragment = new char[requiredChars];
WideCharToMultiByte(CP_UTF8,0,nodeContent,-1,fragment,requiredChars,NULL,NULL);
}
//.........这里部分代码省略.........
示例4: FAILED
bool CDirect3D::SetShaderHLSL(const TCHAR *file)
{
//MUDLORD: the guts
//Compiles a shader from files on disc
//Sets LUT textures to texture files in PNG format.
TCHAR folder[MAX_PATH];
TCHAR rubyLUTfileName[MAX_PATH];
TCHAR *slash;
char *shaderText = NULL;
TCHAR errorMsg[MAX_PATH + 50];
IXMLDOMDocument * pXMLDoc = NULL;
IXMLDOMElement * pXDE = NULL;
IXMLDOMNode * pXDN = NULL;
BSTR queryString, nodeContent;
HRESULT hr;
shaderTimer = 1.0f;
shaderTimeStart = 0;
shaderTimeElapsed = 0;
if(effect) {
effect->Release();
effect = NULL;
}
for(int i = 0; i < MAX_SHADER_TEXTURES; i++) {
if (rubyLUT[i] != NULL) {
rubyLUT[i]->Release();
rubyLUT[i] = NULL;
}
}
if (file == NULL || *file==TEXT('\0'))
return true;
hr = CoCreateInstance(CLSID_DOMDocument,NULL,CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&pXMLDoc));
if(FAILED(hr)) {
MessageBox(NULL, TEXT("Error creating XML Parser"), TEXT("Shader Loading Error"),
MB_OK|MB_ICONEXCLAMATION);
return false;
}
VARIANT fileName;
VARIANT_BOOL ret;
fileName.vt = VT_BSTR;
#ifdef UNICODE
fileName.bstrVal = SysAllocString(file);
#else
wchar_t tempfilename[MAX_PATH];
MultiByteToWideChar(CP_UTF8,0,file,-1,tempfilename,MAX_PATH);
fileName.bstrVal = SysAllocString(tempfilename);
#endif
hr = pXMLDoc->load(fileName,&ret);
SysFreeString(fileName.bstrVal);
if(FAILED(hr) || hr==S_FALSE) {
_stprintf(errorMsg,TEXT("Error loading HLSL shader file:\n%s"),file);
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION);
pXMLDoc->Release();
return false;
}
VARIANT attributeValue;
BSTR attributeName;
hr = pXMLDoc->get_documentElement(&pXDE);
if(FAILED(hr) || hr==S_FALSE) {
_stprintf(errorMsg,TEXT("Error loading root element from file:\n%s"),file);
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION);
pXMLDoc->Release();
return false;
}
attributeName=SysAllocString(L"language");
pXDE->getAttribute(attributeName,&attributeValue);
SysFreeString(attributeName);
pXDE->Release();
if(attributeValue.vt!=VT_BSTR || lstrcmpiW(attributeValue.bstrVal,L"hlsl")) {
_stprintf(errorMsg,TEXT("Shader language is <%s>, expected <HLSL> in file:\n%s"),attributeValue.bstrVal,file);
MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), MB_OK|MB_ICONEXCLAMATION);
if(attributeValue.vt==VT_BSTR) SysFreeString(attributeValue.bstrVal);
pXMLDoc->Release();
return false;
}
if(attributeValue.vt==VT_BSTR) SysFreeString(attributeValue.bstrVal);
queryString=SysAllocString(L"/shader/source");
hr = pXMLDoc->selectSingleNode(queryString,&pXDN);
SysFreeString(queryString);
if(hr == S_OK) {
hr = pXDN->get_text(&nodeContent);
if(hr == S_OK) {
int requiredChars = WideCharToMultiByte(CP_ACP,0,nodeContent,-1,shaderText,0,NULL,NULL);
shaderText = new char[requiredChars];
WideCharToMultiByte(CP_UTF8,0,nodeContent,-1,shaderText,requiredChars,NULL,NULL);
//.........这里部分代码省略.........
示例5: readDatasetFile
//.........这里部分代码省略.........
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());
CHK_ALLOC(bstrQuery);
CHK_HR(pXMLDom->selectSingleNode(bstrQuery, (IXMLDOMNode**)&pDtiNode));
SysFreeString(bstrQuery);
if (pDtiNode)
{
collectionItem->setText(0,queryCollection+"*");
} else
{
collectionItem->setText(0, queryCollection);
}
collectionItem->setData(0, Qt::UserRole, queryStr);
collectionItem->setExpanded(true);
protocolItem->addChild(collectionItem);
SAFE_RELEASE(pCollection);
}
dateItem->addChild(protocolItem);
SAFE_RELEASE(pProtocol);
}
patientItem->addChild(dateItem);
SAFE_RELEASE(pDate);
}
treeWidget->insertTopLevelItem(i, patientItem);
SAFE_RELEASE(pPatient);
}
}
CleanUp:
SAFE_RELEASE(pXMLDom);
SAFE_RELEASE(pPatients);
SAFE_RELEASE(pPatient);
VariantClear(&varFileName);
return SUCCEEDED(hr);
}
示例6: queryNodes
void queryNodes()
{
HRESULT hr = S_OK;
IXMLDOMDocument *pXMLDom = NULL;
IXMLDOMNodeList *pNodes = NULL;
IXMLDOMNode *pNode = NULL;
BSTR bstrQuery1 = NULL;
BSTR bstrQuery2 = NULL;
BSTR bstrNodeName = NULL;
BSTR bstrNodeValue = NULL;
VARIANT_BOOL varStatus;
VARIANT varFileName;
VariantInit(&varFileName);
CHK_HR(CreateAndInitDOM(&pXMLDom));
CHK_HR(VariantFromString(L"stocks.xml", varFileName));
CHK_HR(pXMLDom->load(varFileName, &varStatus));
if (varStatus != VARIANT_TRUE)
{
CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
}
// Query a single node.
bstrQuery1 = SysAllocString(L"//stock[1]/*");
CHK_ALLOC(bstrQuery1);
CHK_HR(pXMLDom->selectSingleNode(bstrQuery1, &pNode));
if (pNode)
{
printf("Result from selectSingleNode:\n");
CHK_HR(pNode->get_nodeName(&bstrNodeName));
printf("Node, <%S>:\n", bstrNodeName);
SysFreeString(bstrNodeName);
CHK_HR(pNode->get_xml(&bstrNodeValue));
printf("\t%S\n\n", bstrNodeValue);
SysFreeString(bstrNodeValue);
SAFE_RELEASE(pNode);
}
else
{
CHK_HR(ReportParseError(pXMLDom, "Error while calling selectSingleNode."));
}
// Query a node-set.
bstrQuery2 = SysAllocString(L"//stock[1]/*");
CHK_ALLOC(bstrQuery2);
CHK_HR(pXMLDom->selectNodes(bstrQuery2, &pNodes));
if(pNodes)
{
printf("Results from selectNodes:\n");
//get the length of node-set
long length;
CHK_HR(pNodes->get_length(&length));
for (long i = 0; i < length; i++)
{
CHK_HR(pNodes->get_item(i, &pNode));
CHK_HR(pNode->get_nodeName(&bstrNodeName));
/*if(0== wcscmp(bstrNodeValue, L"symbol"))
{
}
*/
printf("Node (%d), <%S>:\n", i, bstrNodeName);
SysFreeString(bstrNodeName);
CHK_HR(pNode->get_xml(&bstrNodeValue));
printf("\t%S\n", bstrNodeValue);
SysFreeString(bstrNodeValue);
SAFE_RELEASE(pNode);
}
}
else
{
CHK_HR(ReportParseError(pXMLDom, "Error while calling selectNodes."));
}
CleanUp:
SAFE_RELEASE(pXMLDom);
SAFE_RELEASE(pNodes);
SAFE_RELEASE(pNode);
SysFreeString(bstrQuery1);
SysFreeString(bstrQuery2);
SysFreeString(bstrNodeName);
SysFreeString(bstrNodeValue);
VariantClear(&varFileName);
}