473,657 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MSXML6 C++ unable to locate node

Hi, I am new to using the MSXML functions in C++. I found this on MSDN as
an example of what I wanted to do,
http://msdn2.microsoft.com/en-us/library/ms765465.aspx.

I have tried a number of XPATH examples to try and retrieve the
"><Code>124 55</Code>", but have been unable to do so. The MSDN example works
fine. So, I am wondering if it's a namespace issue?

Any help would be appreciated. Thanks. Jeff

I have changed the code as follows:
int _tmain(int argc, _TCHAR* argv[])
{
CString sResponse = "<?xml version=\"1.0\" encoding=\"utf-8\" ?<string
xmlns=\"http://tempuri.org/\"><InquiryResp onse><Code>1245 5</Code></InquiryResponse ></string>";

//CString sResponse = "<?xml version=\"1.0\" ?><?xml:stylesh eet
type=\"text/xsl\" href=\"stock.xs l\"?><portfol io
xmlns:dt=\"urn: schemas-microsoft-com:datatypes\" <stock
exchange=\"nasd aq\" <name>new</name <symbol>zzzz</symbol <price
dt:dt=\"number\ ">20.313</price </stock <stock exchange=\"nyse \">
<name>zacx corp</name <symbol>ZCXM</symbol <price
dt:dt=\"number\ ">28.875</price </stock <stock exchange=\"nasd aq\">
<name>zaffyma t inc</name <symbol>ZFFX</symbol <price
dt:dt=\"number\ ">92.250</price </stock <stock exchange=\"nasd aq\">
<name>zysmerg y inc</name <symbol>ZYSZ</symbol <price
dt:dt=\"number\ ">20.313</price </stock></portfolio>";
BSTR bstr = sResponse.Alloc SysString();
BSTR bstr2 = '\0';

IXMLDOMDocument *pXMLDom=NULL;
IXMLDOMParseErr or *pXMLErr=NULL;
IXMLDOMNode *pNode=NULL;

VARIANT_BOOL status;
VARIANT var;
HRESULT hr;

CoInitialize(NU LL);

pXMLDom = DomFromCOM();
if (!pXMLDom)
goto clean;

// Load the XML string into the DOM Object
HRCALL(pXMLDom->loadXML(bstr , &status), "");

if (status!=VARIAN T_TRUE)
{
HRCALL(pXMLDom->get_parseError (&pXMLErr),"" );
HRCALL(pXMLErr->get_reason(&bs tr),"");
dprintf("Failed to load DOM from string. %S\n",
bstr);
goto clean;
}

HRCALL(pXMLDom->get_xml(&bstr2 ), "");
dprintf("XML DOM loaded from string:\n%S\n", bstr2);

Sleep(3000);

// Query a single node.
if (bstr2)
SysFreeString(b str2);

bstr2 = SysAllocString( L"//InquiryResponse/Code/*"); // Nothing
//bstr2 = SysAllocString( L"//InquiryResponse/*"); //Nothing
//bstr2 = SysAllocString( L"//*"); // Works
//bstr2 = SysAllocString( L"//string/InquiryResponse/Code"); // Nothing
//bstr2 = SysAllocString( L"//*"); // Too much info
HRCALL(pXMLDom->selectSingleNo de(bstr2, &pNode), "dom->selectSingleNo de:
");
if (!pNode)
{
ReportParseErro r(pXMLDom, "Calling selectSingleNod e ");
}
else
{
dprintf("Result from selectSingleNod e:\n");
if (bstr2)
SysFreeString(b str2);
HRCALL(pNode->get_nodeName(& bstr2)," get_nodeName ");
dprintf("Node, <%S>:\n", bstr2);
if (bstr)
SysFreeString(b str2);
HRCALL(pNode->get_xml(&bstr2 ), "get_xml: ");
dprintf("\t%S\n \n", bstr2);
Sleep(15000);
}

clean:
if (bstr) SysFreeString(b str);
if (&var) VariantClear(&v ar);
if (pXMLErr) pXMLErr->Release();
if (pXMLDom) pXMLDom->Release();

CoUninitialize( );
return 0;

}
Mar 13 '07 #1
3 6894
* j.a. harriman wrote in microsoft.publi c.dotnet.xml:
>I have tried a number of XPATH examples to try and retrieve the
"><Code>1245 5</Code>", but have been unable to do so. The MSDN example works
fine. So, I am wondering if it's a namespace issue?
It is. You have to declare prefixes for the namespaces you are using and
use them in your expressions as appropriate. For example, you could de-
clare "tmp" = ""http://tempuri.org/" and then use /tmp:string in your
example. The MSDN documentation for selectNodes has a C++ example for
how to declare namespace prefixes.
--
Björn Höhrmann · mailto:bj****@h oehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Mar 13 '07 #2
j.a. harriman wrote:
CString sResponse = "<?xml version=\"1.0\" encoding=\"utf-8\" ?<string
xmlns=\"http://tempuri.org/\"><InquiryResp onse><Code>1245 5</Code></InquiryResponse ></string>";
The elements are in the default namespace so with MSXML you need e.g.
(JScript syntax, translate to C++ as needed)
xmlDocument.set Property('Selec tionNamespaces' ,
'xmlns:pf="http ://tempuri.org/"');
xmlDocument.sel ectNodes('pf:st ring/pf:InquiryRespo nse')

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 13 '07 #3
Thanks for pointing me in the right direction.

I've been meaning to update this for others who come along. Or in case I
forget!

The "IXMLDOMDocumen t" (in my original post) had to be a "IXMLDOMDocumen t2"
to access the "setPropert y" function that the "IXMLDOMDocumen t" doesn't have.

And also had to add the following:
CString s = "SelectionNames paces";
BSTR name = s.AllocSysStrin g();
BSTR x = SysAllocString( L"xmlns:pf=\"ht tp://tempuri.org/\"");
VARIANT myVariant;
myVariant.vt = VT_BSTR;
myVariant.bstrV al = x;

so, here was the call:
hr = pXMLDom->setProperty(na me, myVariant);

// Release values
if (x) SysFreeString(x );
if (name) SysFreeString(n ame);
if (&myVariant) VariantClear(&m yVariant);

I also recommend downloading the sample "VariantUse "
http://msdn2.microsoft.com/en-us/lib...38(VS.80).aspx
that proved invaluable for me.
Jeff
"Martin Honnen" wrote:
j.a. harriman wrote:
CString sResponse = "<?xml version=\"1.0\" encoding=\"utf-8\" ?<string
xmlns=\"http://tempuri.org/\"><InquiryResp onse><Code>1245 5</Code></InquiryResponse ></string>";

The elements are in the default namespace so with MSXML you need e.g.
(JScript syntax, translate to C++ as needed)
xmlDocument.set Property('Selec tionNamespaces' ,
'xmlns:pf="http ://tempuri.org/"');
xmlDocument.sel ectNodes('pf:st ring/pf:InquiryRespo nse')

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2538
by: nospam | last post by:
Hey, I was looking at the MS tool VersionCheck and it indicated that I did not have MSXML6. My searching for this file has been fruitless. The only place that I could find it was on a site that required Paypal to download (Checked source code of web page prior to submitting). I do not believe that this is the case for the XML parsers from microsoft. If someone could enlighten me I would appreciate it. Thanx A Plan without Action is...
5
5647
by: apple | last post by:
UDBV8 fp 6a - AIX 5.1 We have scheduled cron jobs to do backups. Periodically and starting to occur more frequently, a backup fails with this error: SQL2072N Unable to bind the shared library "". Reason code: "". We are backing up to a file system on the server. Can't find anything in the logs. We can manually resubmit the job 15 or 30 minutes later and everything works fine. Any ideas on what might be happening? The documentation on...
2
4810
by: TM | last post by:
When I run an ASP.Net application I am getting the following error: "Error while trying to run project: Unable to start debugging on the web server. The project is not configured to be debugged." I checked and made sure the Machine Debug Manager is running on the server, made sure the web.comfit file has debug=true. Mine is: <compilation defaultLanguage="vb" debug="true" /> I also checked the directory executions permissions and it...
5
3080
by: copyco | last post by:
Is there a way to locate a node on the Treeview by a node's fullpath property? Thanks.
8
6505
by: | last post by:
I have the following class : Public Class MyTreeNode Inherits TreeNode Dim mystring As String End Class Now, when I try to do this : ''''''''''''nodes is a TreeNodeCollection, s is string
1
1476
by: bizt | last post by:
Hi, I have an XML document that, at some points, nodes are about several levels deep. For example: <?xml... <root> <node>
4
12600
by: Abubakar | last post by:
Hi, I'm using vs2k5 vc++ (native/unmanaged). I just took a separate copy of a project from source control (vss) and after fixing its dependencies build it and it builds fine. But when I try to run the exe it reports the following strange message: --------------------------- myapp.exe - Unable To Locate Component --------------------------- This application has failed to start because MSVCP80D.dll was not found.
1
2507
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hi, I've looked at a number of examples in the MSXML6 help, but haven't been able to find exactly what I'm looking for. I have the following loaded into a "IXMLDOMDocument2" object. I have a CString sString that I would like to check to see if it matches one of the "Descriptions" below. If it does match, I want to be able to extract the corresponding "Amount" field to use it elsewhere in the program.
1
2409
by: Markw | last post by:
Hi folks I think I've got a variable problem but not 100% sure. Background: I took the CMS example from chapter 6 in "Build your Own Database Driven Website Using PHP&MySQL" and have attempted to modify it for use in my own database. It almost works for me LOL. contact.php returns my dive buddies first and last name and gives me the option to either Edit or Delete them. Currently the delete option is not active. When I choose to edit...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.