Advertisement

Tinyxml C++ Grabbing Id

Started by August 02, 2016 10:07 PM
1 comment, last by Elit3d 8 years, 3 months ago

So I am using tinyxml with c++ and its my first time really parsing with it and xml. Is it possible to, when the text element is pressed, grab the goto attribute and set the dialog id to that attribute. Can't seem to figure out a way to grab the id when the text element is clicked.


<dialogtree>
  <dialog id='0'>
	<name>Boss</name>
    <message name="Boss" text="Testing the dialog system!"></message>
	<responses>
		<response condition="True" goto='1'>
		  response text
		</response>
		<response condition="False" goto='2'>
		  response text
		</response>
		<response condition="False" goto='2'>
		  response text
		</response>
	</responses>
  </dialog>
  <dialog id='1'>
	<name>Player</name>
    <message name="Boss" text="Next message"></message>
	<responses>
		<response condition="True" goto='3'>
		  response text
		</response>
		<response condition="False" goto='4'>
		  response text
		</response>
		<response condition="False" goto='4'>
		  response text
		</response>
	</responses>
  </dialog>
</dialogtree>

I am not sure how you are processing this xml in your code, but generally you would load the xml data into an internal data structure that is easier to work with.

A map data structure could be used where the key is the id and the value is instance of a Dialog class.

I think the key idea is that your xml would get turned into an in memory data structure. For instance you could have a vector of response objects in the Dialog class.

http://www.cprogramming.com/tutorial/stl/stlmap.html

http://www.cplusplus.com/reference/map/map/

Advertisement

I am not sure how you are processing this xml in your code, but generally you would load the xml data into an internal data structure that is easier to work with.

A map data structure could be used where the key is the id and the value is instance of a Dialog class.

I think the key idea is that your xml would get turned into an in memory data structure. For instance you could have a vector of response objects in the Dialog class.

http://www.cprogramming.com/tutorial/stl/stlmap.html

http://www.cplusplus.com/reference/map/map/

Oh so by using the map structure, it will allow me to print out the text along with the next id to make a simple id handler in a way? Thanks I will try this and maybe will paste my code here if anyone else stumbles on this post!

This topic is closed to new replies.

Advertisement