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.

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

where r is XElement

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.