Click here to Skip to main content
15,882,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All

Please find the below XML for reference.

XML
<?xml version="1.0" encoding="utf-16"?>
<Groups count="5">
  <Metadata>
    <FieldDefinitions>
      <FieldDefinition id="12883" name="FISMA Name" alias="Application_Name" />
      <FieldDefinition id="7448" name="Severity" alias="Severity" />
    </FieldDefinitions>
  </Metadata>
  <Group FieldId="12883" Value="Cloud IaaS">
    <Group FieldId="7448" Value="Critical">
      <Aggregates>
        <Aggregate FieldId="7448" Count="12" />
      </Aggregates>
    </Group>
    <Group FieldId="7448" Value="High">
      <Aggregates>
        <Aggregate FieldId="7448" Count="155" />
      </Aggregates>
    </Group>
    <Group FieldId="7448" Value="Medium">
      <Aggregates>
        <Aggregate FieldId="7448" Count="52" />
      </Aggregates>
    </Group>
    <Group FieldId="7448" Value="Low">
      <Aggregates>
        <Aggregate FieldId="7448" Count="61" />
      </Aggregates>
    </Group>
    <Group FieldId="7448" Value="Very Low">
      <Aggregates>
        <Aggregate FieldId="7448" Count="13" />
      </Aggregates>
    </Group>
  </Group>
  <Group FieldId="12883" Value="Monitoring">
    <Group FieldId="7448" Value="Critical">
      <Aggregates>
        <Aggregate FieldId="7448" Count="11" />
      </Aggregates>
    </Group>
    <Group FieldId="7448" Value="High">
      <Aggregates>
        <Aggregate FieldId="7448" Count="32" />
      </Aggregates>
    </Group>
    <Group FieldId="7448" Value="Medium">
      <Aggregates>
        <Aggregate FieldId="7448" Count="11" />
      </Aggregates>
    </Group>
    <Group FieldId="7448" Value="Low">
      <Aggregates>
        <Aggregate FieldId="7448" Count="15" />
      </Aggregates>
    </Group>
    <Group FieldId="7448" Value="Very Low">
      <Aggregates>
        <Aggregate FieldId="7448" Count="10" />
      </Aggregates>
    </Group>
  </Group>
  
</Groups>

End Goal is to by using Linq library I want to fetch the data in a below format of in array

Cloud ISAS
Critical
12
High
155
Medium
52
---etc
Monitoring
Critical
11
High
32
---etc

Code which I wrote:
C#
var lv1s_val = from lv1_date in xdoc1.Descendants("Group")
                     where lv1_date.Attribute("FieldId").Value == "12883"
                      select new
                      {

                        xml_val = lv1_date.Attribute("Value").Value,

                        lv1s1 = from lv1 in xdoc1.Descendants("Group")
                                from a in lv1.Descendants("Aggregate")
                                select new
                                {
                                    fval = lv1.Attribute("Value").Value,
                                    xml_mode = a.Attribute(ff).Value
                                }
                      };



Lvls_val array is giving me only Top header : Cloud IAAS and Monitoring

and Lv1s1 is giving me all in one critical to Very low, there i want it in a loop format and the values should be in sequence else I won't be able to find in output that which critical or high etc will come under which topic.

Please suggest!!

Thanks
-mahendra
Posted

"LINQ parser" might mean "LINQ to XML" and… XML parser. If so, you don't need to "write" it, such parser is already written:
http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx[^].

Read related documentation thoroughly. And I'm afraid even to guess what "xm" could be. Could it possibly mean "XML"? :-)

Look, let me tell you: if you cannot spend some decent time and pay decent attention for your own question and your own problem, how can you hope that someone will volunteer to spend more time on helping you? Nobody want to waste time for nothing.

—SA
 
Share this answer
 
Solved ...

Only issue with my Linq code

Yes.. in question i missed the L which definitely means XML as underneath if you see the question i have posted long XML.

and Linq parser is just means to say Parse XML via Linq code..

if somebody try to see the whole question i have written that i am using Linq library and posted the code for the same.

But still thanks for the suggestion and Library Link I will try to post the question after double check.

Thanks again
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900