4
I’m reading a file XML
where I have to take the values of certain data that are on the same line, example:
I have the following line:
<"Row GenericKitName=\"12000\" QueryID=\"999\" SubQueryID=\"0\" OutboundMessageCode=\"100\" OutboundMessageType=\"CannedMessage\" Description=\"Confirma Panico\" Prompt=\"\" IsHexadecimalConvert=\"False\" Data=\"0\" Name=\"Confirma Panico\" Priority=\"0\" />
How I can search for each item and assign its value?
Example:
Catch Generickitname and the value of 12000 and play on an object.
Catch the Queryid and the value of 999 and play on an object
static void Main(string[] args)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(@"C:\Users\igor.carreiro\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2\XML\Bitologia_19_novembro_2018_NCC.xml");
XmlNodeList listEnvio = xmldoc.SelectNodes("/TICM/DataProvider");
Foward foward = new Foward();
foreach (XmlNode row in listEnvio)
{
XmlNode envio = row.SelectSingleNode("FCM");
if (envio != null)
{
string[] linhas = null;
string linha = envio.FirstChild.OuterXml.ToString();
linhas = linha.Split('<');
List<Foward> listaEnvio = new List<Foward>();
for (int i = 0; i < linhas.Length; i++)
{
foward.GenericKitName = //algo aqui;
foward.QueryID = //algo aqui;
}
}
}
Console.ReadKey();
}
Arquvio XML:
<?xml version="1.0" encoding="utf-8"?>
<TICM>
<DataProvider>
<FCM>
<Row GenericKitName="12000" QueryID="999" SubQueryID="0" OutboundMessageCode="100" OutboundMessageType="CannedMessage" Description="Confirma Panico" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Confirma Panico" Priority="0" />
<Row GenericKitName="12000" QueryID="66" SubQueryID="1" OutboundMessageCode="150" OutboundMessageType="FreeTextMessage" Description="Programa reconexão GPS OK" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Programa reconexão OK" Priority="0" Format="159,8,1,2,167,0,0,0" />
<Row GenericKitName="12000" QueryID="66" SubQueryID="2" OutboundMessageCode="150" OutboundMessageType="FreeTextMessage" Description="Programa violação GPRS OK" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Programa violação OK" Priority="0" Format="159,7,1,2,168,0,0,0" />
<Row GenericKitName="4000" QueryID="67" SubQueryID="0" OutboundMessageCode="43" OutboundMessageType="CannedMessage" Description="Desativa sinais SMART" Prompt="" IsHexadecimalConvert="False" Data="3768" Name="Desativa sinais SMART" Priority="0" />
<Row GenericKitName="5000" QueryID="1" SubQueryID="0" OutboundMessageCode="200" OutboundMessageType="CannedMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="615" Name="Alarm status request" Priority="0" />
<Row GenericKitName="5000" QueryID="2" SubQueryID="0" OutboundMessageCode="200" OutboundMessageType="CannedMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="2816" Name="History status request" Priority="0" />
<Row GenericKitName="5000" QueryID="999" SubQueryID="0" OutboundMessageCode="100" OutboundMessageType="CannedMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Confirmacao de Panico" Priority="0" />
<Row GenericKitName="5000" QueryID="3" SubQueryID="0" OutboundMessageCode="43" OutboundMessageType="CannedMessage" Description="Ativa Panico" Prompt="" IsHexadecimalConvert="False" Data="688" Name="Tulip Ativar Panico" Priority="0" />
<Row GenericKitName="11000" QueryID="27" SubQueryID="0" OutboundMessageCode="94" OutboundMessageType="CannedMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="3371" Name="Bloquear SGPRS" Priority="0" />
<Row GenericKitName="11000" QueryID="28" SubQueryID="0" OutboundMessageCode="94" OutboundMessageType="CannedMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="3339" Name="Desbloquear SGPRS" Priority="0" />
<Row GenericKitName="12000" QueryID="31" SubQueryID="0" OutboundMessageCode="150" OutboundMessageType="FreeTextMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Ativa Panico EGPRS" Priority="0" Format="159,9,2,2,235,60,0,60" />
<Row GenericKitName="12000" QueryID="32" SubQueryID="0" OutboundMessageCode="150" OutboundMessageType="FreeTextMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Desativa Panico EGPRS" Priority="0" Format="159,9,0,2,0,0,0,0" />
<Row GenericKitName="12000" QueryID="33" SubQueryID="0" OutboundMessageCode="150" OutboundMessageType="FreeTextMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Programa 12006 e afins" Priority="0" Format="159,11,1,2,40,300,0,0" />
<Row GenericKitName="12000" QueryID="34" SubQueryID="0" OutboundMessageCode="150" OutboundMessageType="FreeTextMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Ativa modo EVENTO REAL EGPRS" Priority="0" Format="159,11,1,2,40,20,0,0" />
<Row GenericKitName="12000" QueryID="35" SubQueryID="0" OutboundMessageCode="150" OutboundMessageType="FreeTextMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Desativa modo EVENTO REAL EGPRS" Priority="0" Format="159,11,1,2,40,300,0,0" />
<Row GenericKitName="12000" QueryID="36" SubQueryID="0" OutboundMessageCode="150" OutboundMessageType="FreeTextMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Programa 12004" Priority="0" Format="159,11,1,60,0,0,0,0" />
<Row GenericKitName="12000" QueryID="39" SubQueryID="0" OutboundMessageCode="150" OutboundMessageType="FreeTextMessage" Description="" Prompt="" IsHexadecimalConvert="False" Data="0" Name="Programam EGPRS 1 minuto" Priority="0" Format="159,11,1,2,40,60,0,0" />
</FCM>
</DataProvider>
</TICM>
The biggest problem that not only this XML, I believe have more values there, you could put as it is the complete layout?
– novic
@Virgilionovic added!
– Igor Carreiro