Home > OS >  XPath to get attributes containing a specific value, regardless of name
XPath to get attributes containing a specific value, regardless of name

Time:04-01

I have an XML that contains elements like this

  <i:Interaction.Behaviors>
    <behaviors:SplitViewAutoBehavior ToggleAction="{Binding NavBar.ToggleAction, Mode=OneWayToSource}"
                                     CollapseOnClickAction="{Binding NavBar.CollapseOnClickAction, Mode=OneWayToSource}"
                                     CollapseThreshold="{StaticResource SplitViewCollapseThreshold}" />
  </i:Interaction.Behaviors>

I would like to scan the whole XML structure for attributes whose values start with "{Binding", regardless of the name of the attribute.

I have tried so far with several syntax variations, but I haven't found a syntax when the attribute name you look for is unknown, and you look for values instead.

CodePudding user response:

This XPath,

//@*[starts-with(.,'{Binding')]

will select all attributes whose values start with '{Binding', as requested.

  • Related