0
私は応答で取得するxmlを持っていますが、時には属性が来ないので、私がchildnodeを使用しているときに例外が発生しています。属性を使用して解析する方法を知らない助けて。属性名を持つC#でxmlを解析する
XMLは次のとおりです。
<?xml version="1.0"?>
<aws:UrlInfoResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:Response xmlns:aws="http://awis.amazonaws.com/doc/2005-07-11"><aws:OperationRequest><aws:RequestId>2f63dc1c-3ce8-c3fa-0394-e9c1c31c4246</aws:RequestId></aws:OperationRequest><aws:UrlInfoResult>
<aws:Alexa>
<aws:ContactInfo>
<aws:DataUrl type="canonical">bose.com</aws:DataUrl>
<aws:PhoneNumbers>
<aws:PhoneNumber/>
</aws:PhoneNumbers>
<aws:OwnerName/>
<aws:Email/>
<aws:PhysicalAddress/>
<aws:CompanyStockTicker/>
</aws:ContactInfo>
<aws:ContentData>
<aws:DataUrl type="canonical">bose.com</aws:DataUrl>
<aws:SiteData>
<aws:Title>Bose</aws:Title>
<aws:Description>Manufacturers of complete home audio systems such as home theater systems, DVD systems and accessories.</aws:Description>
</aws:SiteData>
<aws:LinksInCount>2368</aws:LinksInCount>
<aws:Keywords>
<aws:Keyword>Consumer Electronics</aws:Keyword>
</aws:Keywords>
</aws:ContentData>
<aws:Related>
<aws:DataUrl type="canonical">bose.com</aws:DataUrl>
<aws:Categories>
<aws:CategoryData>
<aws:Title>Electronics/Audio</aws:Title>
<aws:AbsolutePath>Top/Business/Consumer_Goods_and_Services/Electronics/Audio</aws:AbsolutePath>
</aws:CategoryData>
<aws:CategoryData>
<aws:Title>Shopping/Consumer Electronics</aws:Title>
<aws:AbsolutePath>Top/Shopping/Consumer_Electronics/B</aws:AbsolutePath>
</aws:CategoryData>
<aws:CategoryData>
<aws:Title>Business and Economy/Entertainment and Media</aws:Title>
<aws:AbsolutePath>Top/Regional/North_America/United_States/Massachusetts/Localities/F/Framingham/Business_and_Economy/Entertainment_and_Media</aws:AbsolutePath>
</aws:CategoryData>
</aws:Categories>
</aws:Related>
<aws:TrafficData>
<aws:DataUrl type="canonical">bose.com</aws:DataUrl>
<aws:Rank>11305</aws:Rank>
<aws:UsageStatistics>
<aws:UsageStatistic>
<aws:TimeRange>
<aws:Months>3</aws:Months>
</aws:TimeRange>
<aws:Rank>
<aws:Value>11305</aws:Value>
<aws:Delta>+1450</aws:Delta>
</aws:Rank>
<aws:Reach>
<aws:Rank>
<aws:Value>11392</aws:Value>
<aws:Delta>+1594</aws:Delta>
</aws:Rank>
<aws:PerMillion>
<aws:Value>87.6</aws:Value>
<aws:Delta>-13.94%</aws:Delta>
</aws:PerMillion>
</aws:Reach>
<aws:PageViews>
<aws:PerMillion>
<aws:Value>5.9</aws:Value>
<aws:Delta>-11.85%</aws:Delta>
</aws:PerMillion>
<aws:Rank>
<aws:Value>13240</aws:Value>
<aws:Delta>1318</aws:Delta>
</aws:Rank>
<aws:PerUser>
<aws:Value>2.87</aws:Value>
<aws:Delta>+3%</aws:Delta>
</aws:PerUser>
</aws:PageViews>
</aws:UsageStatistic>
<aws:UsageStatistic>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Rank>
<aws:Value>11396</aws:Value>
<aws:Delta>+175</aws:Delta>
</aws:Rank>
<aws:Reach>
<aws:Rank>
<aws:Value>11602</aws:Value>
<aws:Delta>+176</aws:Delta>
</aws:Rank>
<aws:PerMillion>
<aws:Value>86.9</aws:Value>
<aws:Delta>-0.510%</aws:Delta>
</aws:PerMillion>
</aws:Reach>
<aws:PageViews>
<aws:PerMillion>
<aws:Value>5.93</aws:Value>
<aws:Delta>-1.76%</aws:Delta>
</aws:PerMillion>
<aws:Rank>
<aws:Value>13221</aws:Value>
<aws:Delta>331</aws:Delta>
</aws:Rank>
<aws:PerUser>
<aws:Value>2.92</aws:Value>
<aws:Delta>-1.02%</aws:Delta>
</aws:PerUser>
</aws:PageViews>
</aws:UsageStatistic>
<aws:UsageStatistic>
<aws:TimeRange>
<aws:Days>7</aws:Days>
</aws:TimeRange>
<aws:Rank>
<aws:Value>11570</aws:Value>
<aws:Delta>+394</aws:Delta>
</aws:Rank>
<aws:Reach>
<aws:Rank>
<aws:Value>11949</aws:Value>
<aws:Delta>+569</aws:Delta>
</aws:Rank>
<aws:PerMillion>
<aws:Value>84</aws:Value>
<aws:Delta>-5.640%</aws:Delta>
</aws:PerMillion>
</aws:Reach>
<aws:PageViews>
<aws:PerMillion>
<aws:Value>5.99</aws:Value>
<aws:Delta>-0.41%</aws:Delta>
</aws:PerMillion>
<aws:Rank>
<aws:Value>12951</aws:Value>
<aws:Delta>-102</aws:Delta>
</aws:Rank>
<aws:PerUser>
<aws:Value>3.0</aws:Value>
<aws:Delta>+6%</aws:Delta>
</aws:PerUser>
</aws:PageViews>
</aws:UsageStatistic>
<aws:UsageStatistic>
<aws:TimeRange>
<aws:Days>1</aws:Days>
</aws:TimeRange>
<aws:Rank>
<aws:Value>11837</aws:Value>
<aws:Delta>-215</aws:Delta>
</aws:Rank>
<aws:Reach>
<aws:Rank>
<aws:Value>12937</aws:Value>
<aws:Delta>-21</aws:Delta>
</aws:Rank>
<aws:PerMillion>
<aws:Value>78</aws:Value>
<aws:Delta>-0.40%</aws:Delta>
</aws:PerMillion>
</aws:Reach>
<aws:PageViews>
<aws:PerMillion>
<aws:Value>6.7</aws:Value>
<aws:Delta>+7%</aws:Delta>
</aws:PerMillion>
<aws:Rank>
<aws:Value>11807</aws:Value>
<aws:Delta>-897</aws:Delta>
</aws:Rank>
<aws:PerUser>
<aws:Value>3.8</aws:Value>
<aws:Delta>+7%</aws:Delta>
</aws:PerUser>
</aws:PageViews>
</aws:UsageStatistic>
</aws:UsageStatistics>
<aws:ContributingSubdomains>
<aws:ContributingSubdomain>
<aws:DataUrl>bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>79.41%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>74.98%</aws:Percentage>
<aws:PerUser>2.75</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>community.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>12.41%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>9.10%</aws:Percentage>
<aws:PerUser>2.1</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>global.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>6.49%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>3.08%</aws:Percentage>
<aws:PerUser>1.4</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>pro.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>2.32%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>2.43%</aws:Percentage>
<aws:PerUser>3.0</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>assets.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>4.01%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>1.89%</aws:Percentage>
<aws:PerUser>1.4</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>btu.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>4.24%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>1.75%</aws:Percentage>
<aws:PerUser>1.2</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>accommodations.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.37%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.93%</aws:Percentage>
<aws:PerUser>7.3</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>downloads.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>2.54%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.90%</aws:Percentage>
<aws:PerUser>1.0</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>knowledgebase.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.24%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.74%</aws:Percentage>
<aws:PerUser>9.1</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>gd.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.29%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.66%</aws:Percentage>
<aws:PerUser>6.6</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>em.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.69%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.61%</aws:Percentage>
<aws:PerUser>2.6</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>globalpressroom.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.50%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.58%</aws:Percentage>
<aws:PerUser>3.3</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>hearphones.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.95%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.42%</aws:Percentage>
<aws:PerUser>1.3</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>reseller.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.21%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.39%</aws:Percentage>
<aws:PerUser>5</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>itsm.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.17%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.25%</aws:Percentage>
<aws:PerUser>4</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>auth.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.36%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.21%</aws:Percentage>
<aws:PerUser>1.7</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>build.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.40%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.17%</aws:Percentage>
<aws:PerUser>1.2</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>products.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.43%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.17%</aws:Percentage>
<aws:PerUser>1.1</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>employeepurchase.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.07%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.16%</aws:Percentage>
<aws:PerUser>7</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>professional.bose.com</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0.23%</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.10%</aws:Percentage>
<aws:PerUser>1</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
<aws:ContributingSubdomain>
<aws:DataUrl>OTHER</aws:DataUrl>
<aws:TimeRange>
<aws:Months>1</aws:Months>
</aws:TimeRange>
<aws:Reach>
<aws:Percentage>0</aws:Percentage>
</aws:Reach>
<aws:PageViews>
<aws:Percentage>0.49%</aws:Percentage>
<aws:PerUser>0</aws:PerUser>
</aws:PageViews>
</aws:ContributingSubdomain>
</aws:ContributingSubdomains>
</aws:TrafficData>
</aws:Alexa></aws:UrlInfoResult><aws:ResponseStatus xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:StatusCode>Success</aws:StatusCode></aws:ResponseStatus>
</aws:Response></aws:UrlInfoResponse>
このためにシリアライズを使用することをお勧めだろう
の代わり:XPathはURL(未テストコード)を取得します。 xmlをオブジェクトにシリアル化し、プロパティを読み取ります。 ここから試してみてください:https://msdn.microsoft.com/en-us/library/tz8csy73(v=vs.110).aspx –
あなたはxmlを見ましたか?クラスを宣言してデシリアライズするのはかなり複雑です。あなたは助けをPLZできますか? @Den – raghav
私はいつもxmlやjsonをC#に変換するツールを使用しています。 XMLの場合、私はhttp://xmltocsharp.azurewebsites.net/を使用し、XML出力を貼り付けるだけで、クラスがレンダリングされます。 –