首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Linq to XML,合并属性相同但命名空间不同的元素

Linq to XML,合并属性相同但命名空间不同的元素
EN

Stack Overflow用户
提问于 2011-01-27 22:15:42
回答 1查看 789关注 0票数 0

我想知道是否有可能合并这些具有不同名称空间的元素;

代码语言:javascript
复制
     <imsss:objectives>
        <imsss:primaryObjective objectiveID="ettiquette_completed"/>
          <imsss:objective objectiveID="previous_sco_completed">
              <imsss:mapInfo targetObjectiveID="com.scorm.golfsamples.sequencing.forcedsequential.playing_completed" readNormalizedMeasure="true" readSatisfiedStatus="true" />
          </imsss:objective>
      </imsss:objectives>
      <adlseq:objectives>
        <adlseq:objective objectiveID="ettiquette_completed">
          <adlseq:mapInfo targetObjectiveID="com.scorm.golfsamples.sequencing.forcedsequential.ettiquette_completed" readCompletionStatus="true" writeCompletionStatus="true"/>
        </adlseq:objective>
        <adlseq:objective objectiveID="previous_sco_completed">
          <adlseq:mapInfo targetObjectiveID="com.scorm.golfsamples.sequencing.forcedsequential.playing_completed"  readCompletionStatus="true" writeCompletionStatus="false"/>
        </adlseq:objective>
      </adlseq:objectives>

所以基本上我想以

代码语言:javascript
复制
<imsss:objectives>
        <imsss:primaryObjective objectiveID="ettiquette_completed">
          <imsss:mapInfo targetObjectiveID="com.scorm.golfsamples.sequencing.forcedsequential.ettiquette_completed" readCompletionStatus="true" writeCompletionStatus="true"/>
        </imsss:primaryObjective>
          <imsss:objective objectiveID="previous_sco_completed">
              <imsss:mapInfo targetObjectiveID="com.scorm.golfsamples.sequencing.forcedsequential.playing_completed" readNormalizedMeasure="true" readSatisfiedStatus="true" readCompletionStatus="true" writeCompletionStatus="false/>
          </imsss:objective>
      </imsss:objectives>

目前,我有一个linq查询,它将所有元素和相同的objectiveid属性放在一起;

代码语言:javascript
复制
                XElement seqColl = getSequencingCollection(identifier);
                var ImssObj = seqColl.Element(imsss + "objectives").Elements();
                var AdlObj = seqColl.Element(adlSeq + "objectives").Elements();
                var newEl = from o in ImssObj 
                            join a in AdlObj on o.Attribute("objectiveID").Value equals a.Attribute("objectiveID").Value
                            select new XElement(o.Name, new XAttribute(o.Attribute("objectiveID")), o.Elements(), a.Elements());

( getSequencingCollection方法可以正确地从xml中获取所有排序信息,因为它需要获取本地排序和共享排序)

谢谢大家。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-16 23:02:59

我已经对此做了相当具体的解决方案,如果有人想看它,请让我知道。不过,我无法想象它会对任何人有帮助。但是如果你知道我使用的不是很长的c#函数,而是另一种方法,那么请随时让我知道。谢谢

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4817420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档