|
-
October 10th, 2002, 02:52 AM
#1
selectSingleNode
hi,
i am using MSXML4. I am now implementing schema validation into my XML document. Prior to introducing namespace and xml schema, all the xpath expressions work fine. Once i inserted the xmlns into the xml document root tag, all the XPath expressions failed.
is there something that i am missing or that with namespace, the Xpath expression needs to be more precise or something?
for example:
<?xml version="1.0" ?>
<ROOT>
<TEST dt="2002-10-10" />
<ROOT>
Xpath expression such as "//TEST" works
after introducing namespace and schema validation,
<?xml version="1.0" ?>
<ROOT xmlns="http://www.mynamespace.com" >
<TEST dt="2002-10-10" />
<ROOT>
Xpath expression "//TEST" returns error
code sample:
MSXML2::IXMLDOMElementPtr spRootElem = m_spXmlDoc->documentElement;
MSXML2::IXMLDOMNodePtr spNode = spRootElem->selectSingleNode(_bstr_t(_T("//TEST") ) );
ASSERT (spNode !=NULL);
Appreciate some help here.. thanks
meng
-
October 17th, 2002, 10:12 PM
#2
solved.
CString strNS = _T("xmlns:") + g_strNSprefix + _T("=");
strNS += "'";
strNS += g_strXMLDocNameSpace;
strNS += "'";
m_spXmlDoc->setProperty(_T("SelectionNamespaces") , _bstr_t(strNS) );
try
{
HRESULT hr = m_spXmlSchemaCache->add(_bstr_t(g_strXMLDocNameSpace), _bstr_t(strXSDFullPathFileName));
m_spXmlDoc->schemas = m_spXmlSchemaCache.GetInterfacePtr();
}
catch (...)
{
strErrMsg = _T("Schema add error");
return FALSE;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|