XML file to xDocument with variable element names

  • Thread starter Thread starter Markus Freitag
  • Start date Start date
M

Markus Freitag

Guest
Hello,

how can I read the file into xDocument if panel index and index are flexible.
How I get this inside a object?
<index1 ref1="0001" ref2="001" ref3="6MIN8F">0607777770001</index1>
Request
GetValue(panelnr, index)
GetValue(2, 4)
Response
060777777 0002 002
<order>
060777777
<model>203 777-01 V05</model>
<count>4</count>
<panel1>
<index1 ref1="0001" ref2="001" ref3="6MIN8F">0607777770001</index1>
<index2 ref1="0001" ref2="001" ref3="6MIN8F">0607777770001</index2>
<index3 ref1="0001" ref2="001" ref3="6MIN8F">060777777 0001 001</index3>
<index4 ref1="0001" ref2="002" ref3="6MIN8F">060777777 0001 002</index4>
<index5 ref1="0001" ref2="003" ref3="6MIN8F">060777777 0001 003</index5>
</panel1>
<panel2>
<index1 ref1="0002" ref2="001" ref3="6MIN8F">0607777770002</index1>
<index2 ref1="0002" ref2="001" ref3="6MIN8F">0607777770002</index2>
<index3 ref1="0002" ref2="001" ref3="6MIN8F">060777777 0002 001</index3>
<index4 ref1="0002" ref2="002" ref3="6MIN8F">060777777 0002 002</index4>
<index5 ref1="0002" ref2="003" ref3="6MIN8F">060777777 0002 003</index5>
</panel2>
<panel3>
<index1 ref1="0003" ref2="001" ref3="6MIN8F">0607777770003</index1>
<index2 ref1="0003" ref2="001" ref3="6MIN8F">0607777770003</index2>
<index3 ref1="0003" ref2="001" ref3="6MIN8F">060777777 0003 001</index3>
<index4 ref1="0003" ref2="002" ref3="6MIN8F">060777777 0003 002</index4>
<index5 ref1="0003" ref2="003" ref3="6MIN8F">060777777 0003 003</index5>
</panel3>
<panel4>
<index1 ref1="0004" ref2="001" ref3="6MIN8F">0607777770004</index1>
<index2 ref1="0004" ref2="001" ref3="6MIN8F">0607777770004</index2>
<index3 ref1="0004" ref2="001" ref3="6MIN8F">060777777 0004 001</index3>
<index4 ref1="0004" ref2="002" ref3="6MIN8F">060777777 0004 002</index4>
<index5 ref1="0004" ref2="003" ref3="6MIN8F">060777777 0004 003</index5>
</panel4>
</order>

I want only this value.
<works_order>
060418001

I got it all, see screenshot, why?
//<works_order>
// 060418001
// <model>203 569-01 V05</model>
// <count>3</count>
// <panel1>
// <index1 ref1="0001" ref2="001" ref3="6MIN8F">0604180010001</index1>
// <index2 ref1="0001" ref2="001" ref3="6MIN8F">0604180010001</index2>
// <index3 ref1="0001" ref2="001" ref3="6MIN8F">060418001 0001 001</index3>
// <index4 ref1="0001" ref2="002" ref3="6MIN8F">060418001 0001 002</index4>

bool ret = false;
try
{
//XDoc = XDocument.Parse(xmlContent);
XDoc = XDocument.Load("..\\..\\Order.xml");

Order = XDoc.Element("works_order")?.Value;
Panel = XDoc.Element("works_order")?.Element("panel1")?.Value;


ListPropertiesIndex = (from e in XDoc.XPathSelectElements("//panel1")
select new PropertyIndex
{

Index = e.Element("index1")?.Value, // I need here a index
// But i do not know how much.
//IndexValue = e.Attribute("index1")?.Value,
Ref1 = e.Attribute("ref1")?.Value,
Ref2 = e.Attribute("ref2")?.Value,
Ref3 = e.Attribute("ref3")?.Value,

}).ToList();


With best regards Markus

Continue reading...
 

Similar threads

Back
Top