@fullzero11

Как найти нужные элементы php SimpleXML?

Как получить разом пробежаться по файлу, чтобы получить все значения Header, TextBlock, Text, Content, ToolTip? Ну или хотя бы по очереди..

Пример файла
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:converters="clr-namespace:Trinity.UI.UIComponents.Converters"
             mc:Ignorable="d"  Foreground="{DynamicResource TextBrush}" Background="#474747" Padding="10,0,0,0"
             d:DesignHeight="1500" d:DesignWidth="450">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Template.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <converters:FlagsEnumValueConverter x:Key="flagsEnumValueBooleanConverter"/>
            <converters:EnumBooleanConverter x:Key="EnumBooleanConverter" />
            <converters:PercentConverter x:Key="PercentConverter" />
            <converters:SliderValueToVisibilityConverter x:Key="SliderValueToVisibilityConverter" />
            <converters:BoolToVisibilityConverter x:Key="VisibleWhenTrueConverter" TrueValue="Visible" FalseValue="Collapsed"/>
            <converters:EnumToVisibilityConverter x:Key="EnumToVisibilityConverter" TrueValue="Visible" FalseValue="Collapsed"/>
            <converters:PropertyValueConverter x:Key="propertyValueConverter" />
            <converters:BoolInverterConverter x:Key="BoolInverterConverter" />
            <converters:EnumVisibilityConverter x:Key="EnumVisibilityConverter" />
            <converters:FlagsEnumValueConverter x:Key="flagsEnumValueConverter"/>
            <converters:EnumVisibilityConverter x:Key="enumVisibilityConverter" />
            <converters:BoolToVisibilityConverter x:Key="boolToVisibilityConverter" TrueValue="Visible" FalseValue="Collapsed" />
            <converters:IntToStringConverter x:Key="intToStringConverter"/>
            <converters:EnumBooleanConverter x:Key="enumBooleanConverter" />
            <converters:SliderValueToVisibilityConverter x:Key="sliderValueToVisibilityConverter" />
            <converters:BoolToVisibilityConverter x:Key="HiddenWhenTrueConverter" TrueValue="Collapsed" FalseValue="Visible"/>

        </ResourceDictionary>
    </UserControl.Resources>
    <ScrollViewer>
        <StackPanel Margin="0,10,5,0">

            <GroupBox Header="External Loot System Detected" DockPanel.Dock="Top" Visibility="{Binding GameInfo.IsExternalLootProvider, Converter={StaticResource VisibleWhenTrueConverter}}">
                <StackPanel>
                    <StackPanel Margin="0,6,10,0">
                        <TextBlock TextWrapping="Wrap">Loot system is being controlled by another plugin: <Run Text="{Binding GameInfo.LootProviderName}"/></TextBlock>
                        <TextBlock>Item settings impacted by this have been hidden.</TextBlock>
                    </StackPanel>
                </StackPanel>
            </GroupBox>

            <GroupBox Header="Legendaries" DockPanel.Dock="Top" Visibility="{Binding GameInfo.IsExternalLootProvider, Converter={StaticResource HiddenWhenTrueConverter}}">
                <StackPanel>
                    <StackPanel Margin="0,6,10,0">
                        <WrapPanel Margin="0,0,0,0">
                            <RadioButton Foreground="White" Content="Always Stash" IsChecked="{Binding Items.LegendaryMode, Converter={StaticResource EnumBooleanConverter}, ConverterParameter=AlwaysStash}" />
                            <RadioButton Foreground="White" Content="Ignore" IsChecked="{Binding Items.LegendaryMode, Converter={StaticResource EnumBooleanConverter}, ConverterParameter=Ignore}" />
                            <RadioButton Foreground="White" Content="Only Ancients" IsChecked="{Binding Items.LegendaryMode, Converter={StaticResource EnumBooleanConverter}, ConverterParameter=StashAncients}" />
                            <RadioButton Foreground="White" Content="Use ItemList" IsChecked="{Binding Items.LegendaryMode, Converter={StaticResource EnumBooleanConverter}, ConverterParameter=ItemList}" />
                        </WrapPanel>
                    </StackPanel>
                </StackPanel>
            </GroupBox>

            <GroupBox Header="Gambling">
                <StackPanel Margin="0,6,10,0">
                    <WrapPanel Margin="0,0,0,0">
                        <RadioButton Foreground="White" Content="Enabled" IsChecked="{Binding Items.GamblingMode, Converter={StaticResource EnumBooleanConverter}, ConverterParameter=Enabled}" />
                        <RadioButton Foreground="White" Content="Disabled" IsChecked="{Binding Items.GamblingMode, Converter={StaticResource EnumBooleanConverter}, ConverterParameter=Disabled}" />
                        <RadioButton Foreground="White" Content="Customize" IsChecked="{Binding Items.GamblingMode, Converter={StaticResource EnumBooleanConverter}, ConverterParameter=Selective}" />
                    </WrapPanel>
                    <StackPanel Margin="0,5,0,0" Visibility="{Binding Items.GamblingMode, Converter={StaticResource EnumToVisibilityConverter}, ConverterParameter=Selective}">
                        <ContentPresenter Margin="0,5,0,10" Content="{Binding Items, Converter={StaticResourceExtension propertyValueConverter}, ConverterParameter=GamblingTypes}" Style="{DynamicResource SimpleItemsControlSelector}" />
                        <Slider Template="{DynamicResource LabelledSliderEditable}" 
                            Tag="Never Spend Below"
                            ToolTip="Number of blood shards to always have as a reserve."
                            Interval="100" 
                            Maximum="1000" Minimum="1" SmallChange="100" TickFrequency="1" TickPlacement="None" 
                            Value="{Binding Items.GamblingMinShards}" 
                            HorizontalAlignment="Stretch" Margin="0,0,0,0"
                            MinWidth="175"/>
                        <Slider Template="{DynamicResource LabelledSliderEditable}" 
                            Tag="Save Until Above"
                            ToolTip="Number of blood shards to have before spending."
                            Interval="100" 
                            Maximum="1500" Minimum="1" SmallChange="100" TickFrequency="1" TickPlacement="None" 
                            Value="{Binding Items.GamblingMinSpendingShards}" 
                            HorizontalAlignment="Stretch" Margin="0,0,0,0"
                            MinWidth="175"/>
                    </StackPanel>
                </StackPanel>
            </GroupBox>

            <GroupBox Header="Low Quality Items" Visibility="{Binding GameInfo.IsExternalLootProvider, Converter={StaticResource HiddenWhenTrueConverter}}">
                <StackPanel>
                    <UniformGrid>
                        <CheckBox Content="Pickup Gray Items" ToolTip="Gray Items" IsChecked="{Binding Items.PickupQualities, Converter={converters:FlagsToBoolConverter}, ConverterParameter=Grey}" />
                        <CheckBox Content="Pickup White Items" ToolTip="White Items" IsChecked="{Binding Items.PickupQualities, Converter={converters:FlagsToBoolConverter}, ConverterParameter=White}" />
                        <CheckBox Content="Pickup Blue Items" ToolTip="Blue Items" IsChecked="{Binding Items.PickupQualities, Converter={converters:FlagsToBoolConverter}, ConverterParameter=Blue}" />
                        <CheckBox Content="Pickup Yellow Items" ToolTip="Yellow Items" IsChecked="{Binding Items.PickupQualities, Converter={converters:FlagsToBoolConverter}, ConverterParameter=Yellow}" />
                    </UniformGrid>
                </StackPanel>
            </GroupBox>



        </StackPanel>
    </ScrollViewer>
</UserControl>


Пробовал так, но такой вариант очень не удобный, файлов будет море, и у каждого разные структуры
<?php
$xaml = new SimpleXMLElement(file_get_contents('Items.xaml'));

// Header
foreach ($xaml->ScrollViewer->StackPanel->GroupBox as $text) {
    echo $text["Header"]."<br>\n";
}

// TextBlock
foreach ($xaml->ScrollViewer->StackPanel->GroupBox->StackPanel->StackPanel->TextBlock as $text) {
    echo $text."<br>\n";
}

?>


Этот вариант у меня не работает пока не укажу GroupBox[1], не понятно
<?php
// Content
foreach ($xaml->ScrollViewer->StackPanel->GroupBox->StackPanel->StackPanel->WrapPanel->RadioButton as $text) {
    echo $text['Content']."<br>\n";
}
?>
  • Вопрос задан
  • 570 просмотров
Пригласить эксперта
Ответы на вопрос 2
Wolfnsex
@Wolfnsex Куратор тега PHP
Если не хочешь быть первым - не вставай в очередь!
@krypt3r
Сразу же получить, например, все Header можно с помощью XPath-запроса //Header. Далее в цикле обрабатываете, как вам нужно.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы