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>12455</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/\"><InquiryResponse><Code>12455</Code></InquiryResponse></string>";

	//CString sResponse = "<?xml version=\"1.0\"?><?xml:stylesheet 
type=\"text/xsl\" href=\"stock.xsl\"?><portfolio 
xmlns:dt=\"urn:schemas-microsoft-com:datatypes\">  <stock 
exchange=\"nasdaq\">    <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=\"nasdaq\">    
<name>zaffymat inc</name>    <symbol>ZFFX</symbol>    <price 
dt:dt=\"number\">92.250</price>  </stock>  <stock exchange=\"nasdaq\">    
<name>zysmergy inc</name>    <symbol>ZYSZ</symbol>    <price 
dt:dt=\"number\">20.313</price>  </stock></portfolio>";
	BSTR bstr = sResponse.AllocSysString();
	BSTR bstr2 = '\0';

	IXMLDOMDocument *pXMLDom=NULL;
	IXMLDOMParseError *pXMLErr=NULL;
	IXMLDOMNode *pNode=NULL;

	VARIANT_BOOL status;
	VARIANT var;
	HRESULT hr;

	CoInitialize(NULL);

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

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

	if (status!=VARIANT_TRUE)
		{
		HRCALL(pXMLDom->get_parseError(&pXMLErr),"");
		HRCALL(pXMLErr->get_reason(&bstr),"");
		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(bstr2);

    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->selectSingleNode(bstr2, &pNode), "dom->selectSingleNode: 
");
    if (!pNode)
		{
        ReportParseError(pXMLDom, "Calling selectSingleNode ");
		}
    else
		{
        dprintf("Result from selectSingleNode:\n");
        if (bstr2)
			SysFreeString(bstr2);
        HRCALL(pNode->get_nodeName(&bstr2)," get_nodeName ");
        dprintf("Node, <%S>:\n", bstr2);
        if (bstr)
			SysFreeString(bstr2);
        HRCALL(pNode->get_xml(&bstr2), "get_xml: ");
        dprintf("\t%S\n\n", bstr2);
		Sleep(15000);
		}

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

	CoUninitialize();	
	return 0;

}
0
3/13/2007 5:15:20 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
1887 Views

Similar Articles

[PageSpeed] 55

j.a. harriman wrote:

> 	CString sResponse = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <string 
> xmlns=\"http://tempuri.org/\"><InquiryResponse><Code>12455</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.setProperty('SelectionNamespaces', 
'xmlns:pf="http://tempuri.org/"');
   xmlDocument.selectNodes('pf:string/pf:InquiryResponse')

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
3/13/2007 5:25:39 PM
* j.a. harriman wrote in microsoft.public.dotnet.xml:
>I have tried a number of XPATH examples to try and retrieve the 
>"><Code>12455</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:bjoern@hoehrmann.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/ 
0
bjoern1 (135)
3/13/2007 5:27:31 PM
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 "IXMLDOMDocument" (in my original post) had to be a "IXMLDOMDocument2" 
to access the "setProperty" function that the "IXMLDOMDocument" doesn't have.

And also had to add the following:
CString s = "SelectionNamespaces";
BSTR name = s.AllocSysString();
BSTR x = SysAllocString(L"xmlns:pf=\"http://tempuri.org/\"");
VARIANT myVariant;
	myVariant.vt = VT_BSTR;
	myVariant.bstrVal = x;

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

//  Release values
if (x)	SysFreeString(x);
if (name)	SysFreeString(name);
if (&myVariant)	VariantClear(&myVariant);

I also recommend downloading the sample "VariantUse" 
http://msdn2.microsoft.com/en-us/library/ms177538(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/\"><InquiryResponse><Code>12455</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.setProperty('SelectionNamespaces', 
> 'xmlns:pf="http://tempuri.org/"');
>    xmlDocument.selectNodes('pf:string/pf:InquiryResponse')
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://JavaScript.FAQTs.com/
> 
0
3/21/2007 5:27:08 PM
Reply:

Similar Artilces:

OWA unable to create Calendar Items
Hi. I've got a bit of a problem with Exchange 2000 SP3 on Server 2000, users are unable to create or edit calendar items in their own calendar when logged in through OWA. This only affects a few users, and only the one OWA/Exchange server in the Domain. Any help would be great. "Wojtek" <woj@bakasit.com.au> wrote in news:123mmn975q18m3a@corp.supernews.com: > I've got a bit of a problem with Exchange 2000 SP3 on Server 2000, > users are unable to create or edit calendar items in their own > calendar when logged in through OWA. > > This only af...

Remote location deployments
We are looking at deploying to remote offices overseas, what would the best way be to provide a stable environment which can still function if the direct link to the main server goes down? Hello: Are you looking out for any handhled / PC based remote solution using web services to connect the main office CRM Serve receive the data , store it locally & perodic sync. Regards, Manick ERP solutions Specialist manic_m@yahoo.com "E.H" wrote: > We are looking at deploying to remote offices overseas, what would the best > way be to provide a stable environment which can s...

Unable to load vpmsece.dll
Error msg received when starting Outlook 2000: Unable to load vpmsece.dll Path: c:\Program Files\NAVNT\vpmsece.dll OS: Windows 2000 Professional - all Service Releases and updates installed (OEM - so I don't have original installation disk) Running MS-Outlook Help/"Detect and Repair" does not fix. Does not appear to impact application operation. Mainly an aggravation I'd like to eliminate. Any assistance to repair this problem would be appreciated. ...

http://www.yesverygood.com/, located in China, are specialized in the wholesaling and distributing of varies of DVD, VCD, MOVIE, TV SHOW, etc with high quality and competitive price
http://www.yesverygood.com/, located in China, are specialized in the wholesaling and distributing of varies of DVD, VCD, MOVIE, TV SHOW, etc with high quality and competitive price Dear Sir or Madam. 1.What we are: We, http://www.yesverygood.com/, located in China, are specialized in the wholesaling and distributing of varies of DVD, VCD, MOVIE, TV SHOW, etc with high quality and competitive price. 4. Our Products: Nearly all the popular titles are available in our store, recently we have Sopranos, Stargate, Star trek, Star War, CSI,Baby Einstein, La Femme Nikita,007,West Wing, Friends, Sex ...

How to set default location where attachments are saved?
Hi, How can I indicate default location where I want my files and attachments in Outlook to be saved to? For example, when I click on "save as" to save an attachment, the Save window pops up pointing to my default location (My Documents or something like that)? Thanks. See http://www.swinc.com/odefpath/ Anna Z wrote: > Hi, > How can I indicate default location where I want my files > and attachments in Outlook to be saved to? For example, > when I click on "save as" to save an attachment, the Save > window pops up pointing to my default location (My &...

unable to enable the flag function on outlook 2003
I followed the 'help' instructions to enable the flagging function in outlook and have the flag column show; but I was not able to choose that option (under other options, it was grey) ? What type of email account do you have? -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com Outlook Tips by email: dailytips-subscribe-request@lists.outlooktips.net EMO - a weekly newsletter about Outlook and Exchange: EMO-NEWSLETTER-SUBSCRIBE-REQUEST@PEACH.EASE.LSOFT.COM You can access this newsgroup by...

P R O D U C T R E C A L L
I think Microsoft should bite the bullet and withdraw this product from the market and fix it before it looks any more stupid in the media. Money 2005 errors are beginning to make more news headlines. Keep up the pressure guys, there is light at the end of the tunnel. Email Bill Gates direct to get a better response. I aggree <anonymous@discussions.microsoft.com> wrote in message news:30fa01c4a9a5$d2757eb0$a401280a@phx.gbl... > > I think Microsoft should bite the bullet and withdraw > this product from the market and fix it before it looks > any more stupid in the me...

How to change SQL database location used in Excel 2000 pivot table
I have moved the relevant database from one SQL server to another, changed the relevant ODBC data source which now works for other applications but all of the pivot tables etc linked to the database through Excel cannot be redirected to the new database location. Final solution is to recreate them all from scratch. Not familiar with connections to sql, but can you not re-invoke the pivot table wizard and press the back button in the dialog that results, this should give you the option to re-establish the data -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England nick_hodgeTAKET...

Unable to print to shared printer with normal user accounts
I recently updated one of the client workstations on my network. This workstation hosted two shared printers, a Dell 948 and a HP 1600 Color Laserjet. Both are connected via USB. Prior to upgrading, any user was able to print to either printer from any workstation. However since I have upgraded, all users can print to the Dell from any workstation, but the only users which can print to the HP are the Administator account or user accounts with admin privledges, from workstations other than the one the HP is connected. When a non-admin user trys to print from another workstation the ...

How to detect merged cells with C#
Hi, I do Excel programming first time, and I create a program to detect merged cells , by this way: 1.Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application(); 2.Get every cells in the worksheet, and check it is merged cell, or not. ※There is one worksheet in the Excel only. but the worksheet has 60 columns and 10000 rows. and it take long time to finish detecting a worksheet. Is there any better way to do it? Best, Mars What version of excel are you supporting? xl2002 (it's there in xl2003 for sure!) added an op...

Newbie question
Hi I'm a relative newcomer using Outlook 2000 (not Express) on my desktop computer (Windows ME) in work and a laptop (Windows 98SE) at home. I just use it for calendar, tasks and contacts (no e-mail). I carry a portable hard drive between the two with all my files (Word, etc.) on it. Is there any way I can configure Outlook to set the data file to another drive (i.e. my portable hard drive) rather than drive C on my other computers? It seems that the data is all stored somewhere like C:\WINDOWS\Application Data\Microsoft\Outlook in a .pst file. All I want to do is change that locat...

Unable to send a message, its been trying for 24hrs
...

MS Visual C++ Professional Edition/ Academic Version
I am running Windows XP, Home Edition 5.1 (sp2) on a GenuineIntel Processor (512 MHz, 256 MB RAM). Just when I though I understood (wishful thinking) the myriad of flavors of MS Visual C++, version 6, I now see MSVC++ Professional Edition - Academic Version. My question is, what is the academic version of the professional edition? Does it lack some of the functionality of the regular professional edition. I have been messing with the Express Edition and am wanting to avoid getting anything similar. I like the MFC AppWizard in the Professional (and I think standard) edition. You make a me...

Newbie
Hello, I have Outlook 2002 running in Win98 SE. I'm unable to open the .msg attachments that come from AOL users. Windows opens the "Files of Type" dialog, but I don't know what to put in there. I've done my Usenet homework, but haven't been able to find an answer to this question. TIA ...

oe2000 gens errors: "unable to find server" WTTE
I was using OE2000 as usual for last 6 years till today. Today, Saturday, 4/09/2005, each time I clicked on the icon on the QuickStart part of the taskbar, I got a small message box saying "unable to find server" or words to that effect. I finally right clicked the OE2000 icon on the QuickStart bar and selected properties. To my surprise the shortcut tab showed the path to outlook.exe AND IN ADDITION, THE ARGUMENT " /recycle". I thought that was odd. So I erased the "/recycle" and rebooted the system. Now outlook behaves normally and brings in the email, etc. ...

typing in a new cell and carrying the formatting of the previous c
how can i get the formatting done automatically in line with formatting of the same row evertime i type in a new cell in that row? for example, i have data in spread across A1:E1, and there is a special formatting for this set of data, when i type into F1 i want the same formatting to carry forward. what i am looking for is not a "paste formating" or "Format Painter" option. You could use Conditional Formatting on the whole row, with a condition (for active cell A1) of =NOT(ISBLANK(A1)) -- David Biddulph "fadwa" <fadwa@discussions.microsoft.com...

Outlook Exress
I am using Outlook Express for a separate email account. How can I locate where my datafile is? How can I change the location of my datafile? Thanks Post to the Outlook Express newsgroup news://msnews.microsoft.com/microsoft.public.outlookexpress.general -- Peter Please Reply to Newsgroup for the benefit of others Requests for assistance by email can not and will not be acknowledged. "Christine" <centrol@singnet.com.sg> wrote in message news:hplo7b$5rj$1@mawar.singnet.com.sg... >I am using Outlook Express for a separate email account. > >...

Unable to open attachment in email
When trying to open attachment in email it tell me to "set association panel control" -- Pozzy ------------------------------------------------------------------------ Pozzy's Profile: http://forums.techarena.in/members/251344.htm View this thread: http://forums.techarena.in/windows-vista-mail/1355475.htm http://forums.techarena.in What is the file extension of the attachment? (Eg: .pdf, .doc, .pps). -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "Pozzy" <Pozzy.4eykde@DoNotSpam.com> wrote in message news:...

Unable to Read File #12
I've recently begun receiving error message "Unable to Read File" when trying to open a password protected file. I am able to open the Jan, Feb, Mar and Apr files without problem, but not the May file. Thinking it was a fluke, I spent a half-day yesterday creating a June file, but returned, tried to open yesterday's file, and got the same error message. I have now received the error message on two files (May and June), basically eliminating the possibliity of a random fluke. From reading the Microsoft Knowledge Base, it appears that this may be a known problem. Does...

basic c++ doubt
Is the following code snippet valid? class CSample { ...... ...... TCHAR szBuff[1024] } LPCSTR SampleFn1() { CSample objSample .... .... return objSample.szBuff } void SampleFn2() { .... ... CString strTemp = SampleFn1(); } if not how does the following MFC code work? CString CTime::Format(LPCTSTR pFormat) const { TCHAR szBuffer[maxTimeBufferSize]; struct tm* ptmTemp = localtime(&m_time); if (ptmTemp == NULL || !_tcsftime(szBuffer, _countof(szBuffer), pFormat, ptmTemp)) szBuffer[0] = '\0'; return szBuffer; } It's legal, but it has undefined behavior...

Trusted Locations
Hello, I have an Access 2002 database that is distributed to users operating mostly in a runtime version and do not have the full version of Access. I would like to convert to Access 2007 but the problem that I'm running into is how to deal with the "Trusted Location" in a runtime environment. What is the generally accepted method for assigning the Trusted Location in a runtime environment? Remember these are novice users and I cannot ask them to make registry modifications. Thanks, Vic On Sep 5, 4:37 am, "vic" <v...@showsec.com> wrote: See http://...

Can I use MSComm in C++ console App?? How???
I am tring to write a console app that interfaces with the serial port. I would like to use MSComm if possible. I pretty much know how to do it using an MFC or a dialog app but can't see how to do it for the console. MSCOMM is so much more difficult to use than raw serial port interfacing that it is not clear what value it adds. joe On 19 Oct 2005 16:28:10 -0700, "salsipius" <salsipius@salsipius.com> wrote: >I am tring to write a console app that interfaces with the serial port. >I would like to use MSComm if possible. I pretty much know how to do it >using...

Unable to open attachments #7
Office 2003 Professional XP Professional SP2 I have a end user, who have been experiencing an attachment error for the past couple of weeks. A message will displayed an Excel or PDF attachment with the e-mail, but when the user goes to open up that e-mail or click on the attachment, it would display an error "no object found" or something close to that sort. I would have the end user exit out of Outlook and relaunch, then he would be able to display the attachment. Only one user is having this problem, so it's not a global issue. I was wondering if anyone has experience...

unable to send internal email
Hi All: can you help us with this question: we setup a development Exchange 2000 server with sp3, and about 100 mailboxes, user can connect to the Exchange server fine, we even upload some items from offline PST file to each of the mailboxes, however we can not send each other email, it would stuck in the outbox thus we are unable to track it because exchange server never received it, the Globall address book is working fine, all the services in Exchange server seen to be running any idea ? Thanks for your help ...

C# deserialization mixed element and attribute
Hi, I tried to deserialize the following XML file but failed to get the "Status" value back - always gets null value. The XML file: <cXML timestamp="2001-10-31T23:07:22-08:00" payloadID="1004598442900-8367273815197467070@10.10.13.100"> <Response> <Status code="500" text="Bad Response">500 - Bad Response</Status> </Response> </cXML> This is the Class I created to deserialize the above XML: using System; using System.Collections.Generic; using System.Text; using System.Xml.Serialization; namespace Get...