I have a device that communicates over a persistent TCP socket using XML. Commands are sent to it in XML structure and responses are returned in XML form. The device outputs a root element open such as <OurProtocol>
when connection is made. Each response to commands or query will return unique XML fragments. I have the following code to parse the stream into nodes with XMLTextReader
.
deviceClient.Connect(ipRemoteEndPoint);
deviceStream = deviceClient.GetStream();
XmlTextReader reader = null;
reader = new XmlTextReader(deviceStream);
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an Element.
....
}
}
I was planning on building a state machine to process the nodes as they are detected; with the final destination into C# data classes for consumption by the main program. Is there existing .NET technology that can process the nodes and save me from hand coding state machines for processing the returned XML fragments?
I do have access to a schema file, but thought I couldn't use documemt classes since the source of data is not a full string or file but is instead a network stream.