Game Development Reference
In-Depth Information
XmlNode m_ActorXml;
string m_AssetsDirectory;
const int g_LabelColumnWidth = 160;
int m_LineSpacing;
Panel m_Panel;
public ActorComponentEditor(Panel panel, string projectDirectory)
{
m_ComponentsByName = new Dictionary<string, XmlNode>();
m_Panel = panel;
m_LineSpacing = m_Panel.Font.Height * 2;
m_AssetsDirectory = projectDirectory +
\\Assets
;
XmlDocument componentsXML = new XmlDocument();
componentsXML.Load(m_AssetsDirectory +
\\Editor\\components.xml
);
XmlElement root = componentsXML.DocumentElement;
XmlNodeList components = root.SelectNodes(“child::*”);
foreach (XmlNode component in components)
{
m_ComponentsByName[component.Attributes[“name”].Value] = component;
}
}
Take a look at the use of the XmlElement method, SelectNodes() . The parameter
passed in to this method is an XPath, which is commonly used to specify or search
for elements or attributes of an XML document.
A Quick XPath Tutorial
The ActorComponentEditor makes heavy use of XPath because the same XPath
definition can be used to match elements in the actor XML and the editor compo-
nents
'
XML.
For example, the Division element of the GridRenderComponent in the Grid
actor could be defined as
XPath also allows
searching elements by their number. Since this same element is the third element of
the second child of the root node, the XPath would be “/*[1]/*[3]/*[4]” .
Since XmlElements can be traversed, it is a simple matter to write a utility class to
create XPath descriptions.
/Actor/GridRenderComponent/Division.
class XPathUtility
{
 
Search WWH ::




Custom Search