简体   繁体   中英

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.

I'd like to do it without using xPath, and in 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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