简体   繁体   English

使用 F# 从 XDocument 中提取所有命名空间属性

[英]Extract all namespace attributes from XDocument with F#

I'd like to extract all XAttribute elements with property IsNamespaceDeclaration equal to true from a XDocument.Root and put them in a list for further processing.我想从 XDocument.Root 中提取属性 IsNamespaceDeclaration 等于 true 的所有 XAttribute 元素,并将它们放在列表中以供进一步处理。

I'd like to do it without using xPath, and in F#.我想在不使用 xPath 和 F# 的情况下做到这一点。

Background: I have a restriction (business rule) that certain namespaces must be declared in the root element of XML and not in their respective elements, while some other namespaces must not be declared in the root element.背景:我有一个限制(业务规则),某些命名空间必须在 XML 的根元素中声明,而不是在它们各自的元素中声明,而其他一些命名空间不得在根元素中声明。 Therefore, I have to check their Parents.因此,我必须检查他们的父母。

I have tried some options, but without success.我尝试了一些选择,但没有成功。 Please help.请帮忙。

let namespaceAttributes =
  r.DescendantsAndSelf().Attributes()
  |> Seq.where (fun i -> 
           i.IsNamespaceDeclaration 
           && 
           i.Name.LocalName <> "xsi")

where r is XElement其中 r 是 XElement

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM