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
1339 Views

Similar Articles

[PageSpeed] 43

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 (1778)
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:

office 2003 (size chart to window option location)
I know it was there in 2000 but can't find the option in 2003 to size my chart (as a sheet) to scale with the window. I like that option and it's gone missing. Anyone know where that one went, I've been through the Gizmo, Excel Options, location pretty thoroughly. Actually, I went through all the menu items pretty thoroughly so am probably just overlooking it. Thanks In Advance. Ooops! I'm running 2007 Excel I found the instruction for 2000-2003 (but it's not there in 2007) "enigma" <enigma_epiphany@hotmail.com> wrote in message news:5D86515...

GP 10 fails to store menu toolbar locations
GP version 10.00.1237 Standard The menu/toolbar fails to keep the menu options and buttons in the location I put them in and then lock the toolbars. Sometimes they work, but other times if I work on other programs while GP is starting up after selecting my company to work in when I return to GP the menu is all rearranged, but is still locked. I searched and there was one question directly relating to this and another that references locking the "toolbar", but neither really address the issue or offer a solution. Does anybody from Microsoft have a solution to this problem or...

MSXML6
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 a DayDream Action without a Plan is a Nightmare The latest version of the MS XML parser is 4 (SP2), and is now called the "XML Core Services"....

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! ...

C# extension functions using MSXML?
I'm having performance/memory problems using .NET's XslTransform class so I thought I'd give the MSXML object's a whirl. The question I haven't been able to find in these groups is can I use C# extension functions with the MSXML objects? More specifically to use a C# class which has all my extension functions. I've seen examples where the stylesheet uses the <msxsl:script> element and embeds C# code, but that's not a viable solution for my situation since I'll be maintaining lots of different stylesheets which require the same extension functions. (if ...

Registry Location of Data Files
Hello, I help in managing a pretty large network. As we are sadly using pretty old computers people tend to crash\change computers pretty often. To prevent large data loss they save important mail either on the exchange server or in a personal folder the .pst file of which usually should sit on their private network folder. I have a small scripting applet running on each computer capturing a snapshot of the computer status and saving it to a database on the network. I would like it to also add a column for the location of the outlook data files, so that I can see which users save their .pst fi...

for some reason when i deploy my C# application on windows 2003 occasionaly rdr[0].ToString() hangs where rdr is a System.Data.SqlClient.SqlDataReader. Is there a fix for this? is my visual studio.net
for some reason when i deploy my C# application on windows 2003 occasionaly rdr[0].ToString() hangs where rdr is a System.Data.SqlClient.SqlDataReader. Is there a fix for this? is my visual studio.net out dated? Hi, 1. Does this seem to you to be the right Newsgroup to ask this question ? I would have suggested "microsoft.public.dotnet.framework.adonet". 2. Is there supposed to be a difference between the Message Subject and the Message body ? Isn't the Message Subject supposed to be abbreviated ? 3. As for your question : I strongly doubt if your VS.NET can be called "o...

Application crashing because of chkesp.c error..
Hi, File : i386\chkesp.c Line : 42 The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. What does this error mean ?/ The executable runs perfectly on my machine but when i give it on to the client machine.. it crashes while loading.. I need to solve this issue.. how can I ?? ===== Regards, Jigar Mehta A calling convention is the protocol used to call the function (how parameters are passed and the stack is restored). Y...

Unable to move Contacts to Groups...
Hi. I'm trying to organize and condense my Contacts by moving everyone into Groups. However, unlike OE, WM doesn't seem to allow me to move my individual contacts into groups; it only copies them, leaving me with more clutter than before. Is there any way I can do this in WM or, failing that, any third-party utility to help? Thanks. silas -- Hebrews 11:6 Sounds like you are trying to use folders rather than groups. Have a look at the Groups tutorial: http://www.vistax64.com/tutorials/69738-contact-groups-windows-mail.html --=20 Gary VanderMolen, Microso...

Excel 2003 Error Cannot Locate the Internet Server or Proxy Server
I intalled SP2 from Microsoft. Now my hyperlinks do not work. I get an error Cannot locate the Internet Server or Proxy Server. I re-entered my hyperlinks still doesn't work. I have cable and Internet works fine, but not from Excel. -- don ...

creting event handler client in vc++ for Source c# event
Hello all, Can any one have the source of How to add event handler in unmanaged MFC application for event source which is in Managed(c# class library). Here is the Event Source code : namespace ircConnect { public class IrcConnection { public delegate void MessageEventHandler(object sender,MessageEventArgs e); public event MessageEventHandler MessageIncome; }End Class Event Client void CADONET_MFCDlg::OnFilling() //This is the MFC dialog box event { #pragma push_macro("new") #undef new try { m_IrcConnection =new IrcConnection(); FileWatcherEvents *f=new Fil...

Replace C with A when C is followed by a number, but not otherwise?
I have =Income_Stmt!$c$1&Income_Stmt!c32 in a cell. I want to write a macro that turns column C into column A. I can't use search and replace because this would result in =InAome_Stmt!$A$1&InAome_Stmt!A32. Is there a way to do this? Replace !$C with !$A and !c with !a ************ Anne Troy www.OfficeArticles.com "Excel@shoenfeltconsulting.com" <jimhome@starplace.com> wrote in message news:1130262366.796754.67140@g14g2000cwa.googlegroups.com... >I have =Income_Stmt!$c$1&Income_Stmt!c32 in a cell. > I want to write a macro that turns column C into colu...

TreeView Node: Formatting?
Is there any in-line formatting syntax that can be used to vary the format of a TreeView.Node.Text - so that some of the text is bold and some regular within the same node? Right now, I'm using a subform to show a list of bond trades: "Buys" "Sells" and "Maturations". viz: http://tinyurl.com/25hkn4 (trades are circled in red... note bolding of ParAmount) The joker in the deck is that one "Sell" might link to many Buys. The sale might be 100 mil and sell 10 mil from one buy, 50 mil of another, and so-forth. Each component of that sale has it...

Error: Unable to set the Xvalues property of the series class
I have VBA code that generates a paired-vectors of variant/varian arrays A and B. I want to plot this A vs B on XYScatter chart for 4 different paired-vectors of A and B directly on the Chart. Each o these A (and B) vectors are 360 elements long. e.g. For i = 1 to 40 Ai = -variant/variant array of 360 elements- Bi = -variant/variant array of 360 elements- With ActiveChart .ChartType = xlXYScatter Set ns = .SeriesCollection.NewSeries With ns .name = "A and B " & i .XValues = Ai '->>>> _this_is_where_I_get_the_abovementioned__Error_ - .Values = B...

Autofill Column D based on input in Column C
Is it possible to create a spreadsheet where I type a Category Number in Column C and the name of that category automatically shows in Column D? Specifically, I have an inventory of books for our resource center. When the Inventory was created, it was determined that both the category number and description should be included in every entry. (I haven't worked with it long enough to know how necessary this double-entry might be.) But it sure would be nice not to have to type even the beginning of the category names! Any ideas? Thanks in advance. I'd use another sheet. Put ...

Instalation failed by C:\windows\system32\autoexec.nt
I trialled the latest version of Money but realised I was happy with Money 2000 so I uninstalled the trial version and attemped to reinstall Money 2000 only to get a window headed 16 bit Windows Subsysytem which read C:\windows\system32\autoexec.nt The system file is not suitable for running msdos or microsoft windows applications. Choose 'close' to terminate the application. Clicking close did nothing and setup would not activate on the Money CD ...

Unable to open Outlook XP Email
I began having problems when trying to open email with attachments in Outlook XP (running Windows XP Pro) about 3 weeks ago. When I try to open email with attachments, my PC will sometimes hang-up, requiring a reboot, even after which the email will not open (known safe source). The frequency of occurrence seems to be going up. Any help on how to fix this problem would be greatly apprecated. Thanks. Glenn Try it again with the virusscanner and virusscanner integration disabled. -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Me...

Unable to Print Colored Text
Although print preview shows my colored font correctly, when it prints, it prints in black. My graphics and page color print correctly, however. I have researched this problem and found one instruction to go to the tools menu and unclick a color matching selection, but I can't find the tools menu to try this fix. I then researched that problem (no tools menu) and got nowhere. I am totally frustrated in trying to resolve this problem. I have Word 2007 and Windows 7. I have installed all available updates. Any help you can give me would be appreciated. Thanks. Maureen ...

Running out of disk space on C:
Our SBS2003 has a RAID-5 HDD partitioned 20GB C: for the system and 80GB E: for user data. This was ok originally, but C: is gradually filling up and is now 17.5GB used (D&S 1.7GB, MSDE 0.5GB, PFiles 5GB, Windows 6.5GB, Pagefile 3GB) which caused my latest software update to run out of disk space. I'm reluctant to try to resize partitions (don't trust Partition Magic 7 with a server RAID array), and have done what I can to reduce the size of C:, ie * located user SQL DBs and SBS Client Apps on E: not C: * with Disk Cleanup, removed everything offered * also deleted o...

MSXML6 SP1 broke my SAXWriter
I upgraded my application from MSXML4 to MSXML6, and everything was working fine. My project uses MXXMLWriter60, SAXContentHandler and XMLSchemaCache60, etc. Then I installed MSXML6 sp1. The XML document generated from my application has two problems: 1. "????" marks appears inside XML in various places, likely at the end of the stream buffer (?) 2. The first block of attributes are always added properly. Then the second block of attributes contain the attributes from the previous element. Here is an example of before and after: Good XML with MSXML6: <?xml version="1...

I am unable to send/recieve messages
I am unable to send/recieve messages Bummer. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. After furious head scratching, raghu asked: | I am unable to send/recieve messages What happens when you try? Also, what sort of account(s) do you have setup in Outlook? "raghu" <raghu@discussions.microsoft.com> wrote in message news:36586D9C-14AB-45FC-A549-663B3817530D@microsoft.com... >I am unable to send/recieve messages "raghu"...

printing data from different location in same worksheet
hi community is it possible to print data from different location example: i want to print colum B and data from colum H when I used ctrl+select and do a Print Preview, I can see both columns But when I use Print Option: "Print Selection", I can only see column B and column H now goes to next page can anybody please tell me how to do such that I able to view both columns in the same Preview Page taken from the File Menu > Print.... thanks community for the help :) -- oldLearner57 Did you try File -> Page Setup -> Sheet Tab Select the column B data for Columns to re...

Unable to receive email
I get this message when trying to access mail: Account: 'Dorothy Groce', Server: 'incoming.verizon.net', Protocol: POP3, Server Response: '-ERR invalid command', Port: 110, Secure(SSL): No, Server Error: 0x800CCC90, Error Number: 0x800CCC18 "SamG" <SamG@discussions.microsoft.com> wrote in message news:074163D2-0452-4B03-BDFC-4B9EDD7D4F83@microsoft.com... >I get this message when trying to access mail: > > Account: 'Dorothy Groce', Server: 'incoming.verizon.net', Protocol: POP3, > Server Response: '-ERR in...

Money 2005 'C' Column
I have several bank accounts that I track on my computer using Microsoft Money 2005; I store the data online, so that it can be accessed and edited by two users. A co-worker also uses the same data online; the deposits and checks written show up correctly, no matter which of us has entered the information. What does not show up is an entry in the reconciliation column. The reconciliation is done on my system. Then, the entries that are marked with a “C,” don’t display a “C” for my co-worker. She can never tell which entries have cleared the bank. It is a puzzle why all the informa...

Unable to log into mailbox after move
I moved a mailbox from one store to another on the same server (Exchange 2003 Enterprise on a Windows 2000 server). In the past I've been able to access mailboxes within 20 minutes, but I am still unable to access this one. I've forced replication in Active Directory Sites & Services many times, but after several hours I am unable to access the mailbox (I get a "The mailbox does not exist on this server" error). Is there a better way to force this to go through, or is there something else I should be looking at? "Joe Grover" <grover.joe@acd.net> wrot...