我想提取 的值ea_sourceName
以及ea_targetName
的值何时ea_type
为Aggregation
。
<UML:Association xmi.id="EAID_018EEEB3_9A6B_4102_85C8_3A78261E9AA4" visibility="public" isRoot="false" isLeaf="false" isAbstract="false">
<UML:ModelElement.taggedValue>
<UML:TaggedValue tag="style" value="3" />
<UML:TaggedValue tag="ea_type" value="Aggregation" />
<UML:TaggedValue tag="direction" value="Source -> Destination" />
<UML:TaggedValue tag="linemode" value="3" />
<UML:TaggedValue tag="linecolor" value="-1" />
<UML:TaggedValue tag="linewidth" value="0" />
<UML:TaggedValue tag="seqno" value="0" />
<UML:TaggedValue tag="headStyle" value="0" />
<UML:TaggedValue tag="lineStyle" value="0" />
<UML:TaggedValue tag="ea_localid" value="8" />
<UML:TaggedValue tag="ea_sourceName" value="Course" />
<UML:TaggedValue tag="ea_targetName" value="Sem_Progarm" />
<UML:TaggedValue tag="ea_sourceType" value="Class" />
<UML:TaggedValue tag="ea_targetType" value="Class" />
<UML:TaggedValue tag="ea_sourceID" value="18" />
<UML:TaggedValue tag="ea_targetID" value="19" />
<UML:TaggedValue tag="virtualInheritance" value="0" />
</UML:ModelElement.taggedValue>
我试过这段代码,但它没有返回任何东西。我想要的是一个包含ea_sourceName
like等值Course
的列表
static XNamespace ns2;
ns2 = @"omg.org/UML1.3";
XDoucument MyXmiFile = XDocument.Load(path);
string Relation = "Association";
var q = from p in this.MyXmiFile.Descendants(ns2 + Relation)
select p;
var m = from p in q.Descendants(ns2 + "TaggedValue")
where p.Attribute("tag").Value == "ea_type" && p.Attribute("value").Value == "Aggregation"
select p;
var s = from p in m
let P1 = p.Attribute("tag").Value
where P1 == "ea_sourceName"
select p.Attribute("value").Value;
List<string> Result = new List<string>(s.ToList());