簡體   English   中英

使用 F# 從 XDocument 中提取所有命名空間屬性

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

我想從 XDocument.Root 中提取屬性 IsNamespaceDeclaration 等於 true 的所有 XAttribute 元素,並將它們放在列表中以供進一步處理。

我想在不使用 xPath 和 F# 的情況下做到這一點。

背景:我有一個限制(業務規則),某些命名空間必須在 XML 的根元素中聲明,而不是在它們各自的元素中聲明,而其他一些命名空間不得在根元素中聲明。 因此,我必須檢查他們的父母。

我嘗試了一些選擇,但沒有成功。 請幫忙。

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

其中 r 是 XElement

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM