Archived

This topic is now archived and is closed to further replies.

C++ XML selectSingleNode

This topic is 5047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The following is a portion of my C++ code; I am trying to get selectSingleNode to find the node CPlayer?
BSTR bsNodeName;
MSXML2::IXMLDOMNode *pXmlNode;bstr = SysAllocString(L"//CPlayer[1]/*");

hr = pXMLDom->selectSingleNode(bstr, &pXmlNode);
pXmlNode->get_nodeName(&bsNodeName);
The following is the XML file:
<?xml version="1.0"?>
<CLevel xmlns="http://tempuri.org/Level015.xsd">

	<CPlayer>
		<sName>Human</sName>
		<CStarship>
			<sMeshName>WhiteStar-Low.x</sMeshName>
			<vecPosition>
				<fX>0.0</fX>
				<fY>0.0</fY>
				<fZ>0.0</fZ>
			</vecPosition>
		</CStarship>
	</CPlayer>
	<CPlayer>
		<sName>Computer</sName>
		<CStarship>
<sMeshName>WhiteStar-Low.x</sMeshName>
			<vecPosition>
				<fX>0.0</fX>
				<fY>0.0</fY>
				<fZ>0.0</fZ>
			</vecPosition>
		</CStarship>
	</CPlayer>
</CLevel>

[edited by - Sean Doherty on February 21, 2004 8:02:11 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What''s the problem that you''re experiencing at the moment ? (btw, I suggest you seperate the code & the xml into 2 seperate source tags ... easier to tell what''s what). I don''t know to much about MSXML (personally prefer Xerces for DOM work) but it might be that selectSingleNode only selects nodes that are it''s immediate childres (ie that you might need to to be at the CLevel level) - the other thing is, are you sure that you''ve got the right format for the string? looks like you''re trying to use some kind of perl style reg exp?! what happens if you just try

bstr = SysAllocString(L"CPlayer"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Damned smilies in this place are a liability! that smiley should have been a bracket followed by a semi-colon:

bstr = SysAllocString( L"CPlayer" ) ;

Share this post


Link to post
Share on other sites
CPlayer does not seem to work either? It does not find the Node?


bstr2 = SysAllocString(L"CPlayer");
hr = pXMLDom->selectSingleNode(bstr2, &pXmlNode);
pXmlNode->get_nodeName(&bsNodeName);


[edited by - Sean Doherty on February 21, 2004 7:15:22 PM]

Share this post


Link to post
Share on other sites
The problem went away when I remove the schema validation from the xml file? The following was removed from CLevel:

Is there any say to keep the schema and possibly point to it in the same directory as the xml file? Keep in mind that this is a client side game; not a web application.


xmlns="http://tempuri.org/Level015.xsd"




[edited by - Sean Doherty on February 22, 2004 10:58:15 AM]

Share this post


Link to post
Share on other sites