Linq To Xml 变通方式获取某个节点或子节点下所有属性:

 

 
  
  1. //获取节点属性总数 
  2. private int GetAttributeNumber(XElement el) 
  3.     int num = 1; 
  4.     XAttribute firstAttr = el.FirstAttribute; 
  5.     if (firstAttr == null
  6.     { 
  7.         return 0; 
  8.     } 
  9.     else 
  10.     { 
  11.         XAttribute nextAttr = firstAttr.NextAttribute; 
  12.         for (int i = 0; i < 20; i++) 
  13.         { 
  14.             if (nextAttr == null
  15.             { 
  16.                 break
  17.             } 
  18.             else 
  19.             { 
  20.                 nextAttr = nextAttr.NextAttribute; 
  21.                 num++; 
  22.             } 
  23.         } 
  24.     } 
  25.     return num;