如何为此xm编写Linq解析器 [英] How do I write the Linq parser for this xm

查看:161
本文介绍了如何为此xm编写Linq解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All



请查看以下XML供参考。



Hello All

Please find the below XML for reference.

<?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>



结束目标是通过使用Linq库我想以下面的数组格式获取数据



Cloud ISAS

重要

12



155

中等

52

---等

监控

重要

11



32

---等等



我写的代码:


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:

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数组只给我顶部标题:云IAAS和监控



和Lv1s1给我所有的一个关键到非常低,我希望它以循环格式,值应该是顺序其他我将无法在输出中找到哪个关键或高等等将在哪个主题下。



请建议!!



谢谢

-mahendra




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

推荐答案

LINQ解析器可能意味着LINQ to XML和... XML解析器。如果是这样,你不需要写它,这样的解析器已经写好了:

http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx [ ^ ]。



彻底阅读相关文档。而且我甚至害怕猜测xm可能是什么。它可能意味着XML吗? :-)



看,让我告诉你:如果你不能度过一些体面的时间并为自己的问题和自己的问题付出相当的关注,你怎么能希望有人会自愿花更多的时间来帮助你吗?没有人愿意浪费时间。



-SA
"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


解决了......



仅发行我的Linq代码



是..有问题我错过了如果你看到我发布了长XML的问题,L肯定意味着XML在下面。



和Linq解析器只是说通过Linq代码解析XML。



如果有人试图看到我写的整个问题我正在使用Linq库并发布相同的代码。



但仍然感谢你的建议和图书馆链接我会在仔细检查后发布问题。



再次感谢
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


这篇关于如何为此xm编写Linq解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆