如何将数组转换为SimpleXMLElement对象

时间:2015-12-11 12:02:27

标签: php

我有如下的数组

Array
(
    [@attributes] => Array
        (
            [Id] => 925343664
            [FloorplanID] => 617454
            [BuildingID] => 
        )

    [Unit] => Array
        (
        )

    [Comment] => Array
        (
        )

    [Availability] => Array
        (
            [VacancyClass] => Occupied
            [MadeReadyDate] => Array
                (
                    [@attributes] => Array
                        (
                            [Month] => 1
                            [Day] => 24
                            [Year] => 2016
                        )

                )

        )

)

我想将此数组转换为SimpleXMLElement Object,如下所示

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [Id] => 925832659
            [FloorplanID] => 617454
            [BuildingID] => 
        )

    [Unit] => SimpleXMLElement Object
        (
        )

    [Comment] => SimpleXMLElement Object
        (
        )

    [Availability] => SimpleXMLElement Object
        (
            [VacancyClass] => Occupied
            [MadeReadyDate] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [Month] => 1
                            [Day] => 12
                            [Year] => 2016
                        )

                )

        )

)

我尝试了一些谷歌搜索,但我没有找到任何解决方案 我怎样才能做到这一点 ?任何人都可以为此解决问题吗?

1 个答案:

答案 0 :(得分:1)

void GetText(object sender, SelectionChangedEventArgs args)
{
    ComboBoxItem item1 = cb1.SelectedItem as ComboBoxItem);
    ComboBoxItem item2 = cb2.SelectedItem as ComboBoxItem);

    if(item1 == null || item2 == null)
       return;
    //convert to # with your tryParse
    fillTextBox(item1, item2);
}

类似的东西;)