C++ XML selectSingleNode

Started by
4 comments, last by Sean Doherty 20 years, 1 month ago
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]
_______________________________________Understanding is a three edged sword...Freelance Games - Home of XBLIG Starchonwww.FreelanceGames.com
Advertisement
The xml didn''t post properly to the forum; it should be ok now. Does anyone have an anwser?

Thanks
_______________________________________Understanding is a three edged sword...Freelance Games - Home of XBLIG Starchonwww.FreelanceGames.com
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" 
Damned smilies in this place are a liability! that smiley should have been a bracket followed by a semi-colon:
bstr = SysAllocString( L"CPlayer" ) ; 
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]
_______________________________________Understanding is a three edged sword...Freelance Games - Home of XBLIG Starchonwww.FreelanceGames.com
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]
_______________________________________Understanding is a three edged sword...Freelance Games - Home of XBLIG Starchonwww.FreelanceGames.com

This topic is closed to new replies.

Advertisement