开发者

XElements by Attribute Name

I need to write a Linq query to get XElements based on Attribute Name.

The XMl is not a structured one.. The attribute may there at the top of some XML node or any where in the xml ?

Well actually it is the word document the xml file document.xml there will be places it uses the r:Id ,Now i need to get all the Elements which contain this attribute !

Below is the XML

> <w:p w:rsidR="00302209"
> w:rsidRDefault="005C326E"
> w:rsidP="00302209">
> - <w:pPr>   <w:framePr w:w="3186" w:h="1701" w:hSpace="142"
> w:wrap="around" w:vAnchor="page"
> w:hAnchor="page" w:x="8688"
> w:y="11449" />    <w:spacing
> w:line="240" w:lineRule="exact" /> 
> - <w:rPr>   <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"
> />    <w:szCs w:val="24" />   
> </w:rPr>   </w:pPr>
> - <w:hyperlink r:id="rId6" w:history="1">
> - <w:r w:rsidR="00302209">
> - <w:rPr>   <w:rStyle w:val="Hyperlink" />    <w:rFonts
> w:ascii="Times New Roman"
> w:hAnsi="Times New Roman" />   
> <w:szCs w:val="24" />    </w:rPr>  
> <w:t>dd.com</w:t>    </w:r>  
> </w:hyperlink>   </w:p> <w:sectPr
> w:rsidR="001D3CA8"
> w:rsidRPr="00E275EA"
> w:rsidSect="00522450">  
>开发者_JS百科 <w:headerReference w:type="even"
> r:id="rId7" />    <w:headerReference
> w:type="default" r:id="rId8" />   
> <w:footerReference w:type="even"
> r:id="rId9" />    <w:footerReference
> w:type="default" r:id="rId10" />   
> <w:headerReference w:type="first"
> r:id="rId11" />    <w:footerReference
> w:type="first" r:id="rId12" />   
> <w:pgSz w:w="11907" w:h="16840"
> w:code="9" />    <w:pgMar w:top="1701"
> w:right="3572" w:bottom="510"
> w:left="1134" w:header="567"
> w:footer="238" w:gutter="0" />   
> <w:cols w:space="708" />    <w:titlePg
> />    </w:sectPr>

Regards Francis P.


Sure, it's easy:

var elements = doc.Descendants().Where(x => x.Attribute("Foo") != null);

Let me know if that's not what you were after...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜