I have a set of files that have the structure of an XML file (parent-child nodes), but are not the conventional XML files. The structure looks like this:
<_ML_Message>
<TransactionId Value="0x02" />
<GroupNo Value = "2" />
<AbortOnError Value = "255" />
<MessageBody>
<GetProcParameterRequest>
<ServerId Value="0xFFFFFFFFFFFF" />
<ParameterTreePath Qty = "1" >
<_OctetString Value="0x0000800029FF" />
</ParameterTreePath>
</GetProcParameterRequest>
</MessageBody>
<CRC16 Value = "0" />
<EndOfMlMessage />
</_ML_Message>
<_ML_Message>
<TransactionId Value="0x03" />
<GroupNo Value = "3" />
<AbortOnError Value = "255" />
<MessageBody>
<CloseRequest>
</CloseRequest>
</MessageBody>
<CRC16 Value = "0" />
<EndOfMlMessage />
</_ML_Message>
Since I cannot use the standard C# XML libraries (for example, XMLDocument) on this file I am trying to parse it and use it like a normal text file,
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string xml = File.ReadAllText(baseDirectory + "MyXMLFile.xml");
if (xml.StartsWith("TransactionId"))
{
//Try to get the value
}
But parsing it this way is cumbersome at the moment, I was wonder if there are alternative ways to parse this kind of a file.
<! DOCTYPE...>you need to make it a valid XML file? Or is it invalid in other ways? (Doesn't follow the XML specification for comments, CData, Quotes, etc).<dummy></dummy>, the stuff you posted would parse fine. With XElement.Parse() you don't need a doctype.