Hi folks,
I'm trying to write an XMLHandler for my epos app. The XML file (which is received by a network stream) will include multiple "operations" which may include updating the product database or opening the cash drawer etc..
My sample XML file looks like this:
<paypointXML>
<op>
<command>opendrawer</command>
</op>
<op>
<command>updateDatabase</command>
<item>
<desc>Big Book of Tales</desc>
<price>5.99</price>
<category>100</category>
</item>
<item>
<desc>Small book of Rhymes</desc>
<price>1.99</price>
<category>100</category>
</item>
</op>
</paypointXML>
So far my c# code looks like this:
private void XMLHandler(string data)
{
StringReader str = new StringReader(data);
XPathDocument doc = new XPathDocument(str);
XPathNavigator nav = doc.CreateNavigator();
// Compile a standard XPath expression
XPathExpression expr;
expr = nav.Compile("/paypointXML/op/command");
XPathNodeIterator iterator = nav.Select(expr);
// Iterate on the node set
try
{
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
if (nav2.Value == "opendrawer")
{
Device.drawerkick();
}
else if (nav2.Value == "updateDatabase")
{
//I want this to iterate through all the nodes inside THIS paticular op node..
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Now, as you can see above my c# code will only ever parse the opendrawer command. I am lost when it comes through iterating through the current node...
Can anyone please help me on how to achieve the above with regarding update my database?
Maybe my XML file struct could be better? Maybe the item details should be inside the command node?
Your help is appreciated thanks
Jonny