0

次のxml構造があり、このxmlをCLRオブジェクトに変換したいのですが、行き詰まります。

<?xml version="1.0" encoding="utf-8"?>
<SymbolData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            assembly="C:\adCenter\debug\DLLs\Microsoft.Advertiser.CampaignManagement.BusinessRules.dll">
  <sourceFiles>
    <document id="1" 
              url="d:\7018\4579\Sources\Live\Microsoft.Advertiser.CampaignManagement.BusinessRules\AdExtensionValidators\AdExtensionValidationBatchErrors.cs" 
              language="3f5162f8-07c6-11d3-9053-00c04fa302a1" 
              languageVendor="994b45c4-e6e9-11d2-903f-00c04fa302a1" 
              documentType="5a869d0b-6611-11d3-bd2a-0000f80849bd" />    
    <document id="2" 
              url="d:\7018\4579\Sources\Live\Microsoft.Advertiser.CampaignManagement.BusinessRules\AdExtensionValidators\AdExtensionValidationBatchErrors.cs" 
              language="3f5162f8-07c6-11d3-9053-00c04fa302a1" 
              languageVendor="994b45c4-e6e9-11d2-903f-00c04fa302a1" 
              documentType="5a869d0b-6611-11d3-bd2a-0000f80849bd" />        
  </sourceFiles>
  <method name="Microsoft.Advertiser.CampaignManagement.BusinessRules.AdExtensionValidators.AdExtensionValidationBatchErrors::.ctor" 
          token="0x600000c">
    <sequencePoints>
      <seqPoint ilOffset="0" sourceId="1" startRow="10" startColumn="9" endRow="10" endColumn="106" />
      <seqPoint ilOffset="11" sourceId="1" startRow="12" startColumn="9" endRow="12" endColumn="136" />
      <seqPoint ilOffset="22" sourceId="1" startRow="14" startColumn="9" endRow="14" endColumn="181" />
      <seqPoint ilOffset="33" sourceId="1" hidden="true" startRow="16707566" startColumn="0" endRow="16707566" endColumn="0" />
    </sequencePoints>
    <rootScope implicit="true" startOffset="0" endOffset="40">
      <scope startOffset="0" endOffset="40" isReconstructedDueToDiasymreaderBug="true" />
    </rootScope>
    <symAttributes />
    <csharpCustomDebugInfo version="4">
      <entries>
        <usingForward version="4" tokenToForwardTo="0x6000001" />
      </entries>
    </csharpCustomDebugInfo>
  </method>
  <method name="Microsoft.Advertiser.CampaignManagement.BusinessRules.AdExtensionValidators.AdExtensionValidationError::ToString" token="0x600000f">
    <sequencePoints>
      <seqPoint ilOffset="0" sourceId="2" startRow="167" startColumn="13" endRow="167" endColumn="110" />
    </sequencePoints>
    <rootScope implicit="true" startOffset="0" endOffset="33">
      <scope startOffset="0" endOffset="33" isReconstructedDueToDiasymreaderBug="true" />
    </rootScope>
    <symAttributes />
    <csharpCustomDebugInfo version="4">
      <entries>
        <usingForward version="4" tokenToForwardTo="0x600000d" />
      </entries>
    </csharpCustomDebugInfo>
  </method>


</SymbolData>

同じことを実現するために次のコードを記述しましたが、メソッドセクションをクエリできません。 たとえば、documentIDとSourceIDが同じであるすべてのメソッドをロードしたいとします。

public class ClassDetails
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }
    public class AssemblyDetails
    {
        public string DllName { get; set; }
        public List<ClassDetails> Classes { get; set; }
        public List<string> Methods { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var document = XDocument.Load("test11.xml");
            var query = from descendantNode in document.Descendants("sourceFiles")
                        select new AssemblyDetails()
                        {
                            DllName = document.Root.Attribute("assembly").Value,
                            Classes = (from x in document.Descendants("document")
                                      select new ClassDetails
                                      {
                                          Id=x.Attribute("id").Value,
                                          Name=x.Attribute("url").Value
                                      }).ToList(),
                            Methods = (from y in document.Descendants("method").Elements("seqPoint")
                                     where y.Attribute("sourceId").Value=="documentID"
                                     select y.Document.Root.Attribute("name").Value).ToList()
                       };

            int i=10;
        }
4

1 に答える 1

2
XDocument xdoc = XDocument.Load(path_to_xml);
var documentIds = xdoc.Descendants("document")
                      .Select(d => (int)d.Attribute("id"));
                      .ToList();

var methodNames = xdoc
    .Descendants("method")
    .Where(m => m.Descendants("seqPoint")
                 .Any(sp => documentIds.Contains((int)sp.Attribute("sourceId"))))
    .Select(m => (string)m.Attribute("name"));

最初のクエリはすべてのドキュメントIDを取得します。

2番目のクエリは、指定されたドキュメントの少なくとも1つを持つメソッドのメソッド名を取得seqPointsourceIdます。

于 2012-11-10T19:40:15.160 に答える