将xml解析为mysql

时间:2011-12-11 20:54:40

标签: php mysql xml simplexml

我有一个XML feed,我需要解析其中的一些并将其存储到MySQL表中,但我面对的是一种新的XML(我不擅长这个) 这是我从这个地址使用simplexml_load_file打开的XML: It's a pubmed journal publication我需要存储作者列表和其他一些内容,但是如果能够访问它我可以管理。 非常感谢

  SimpleXMLElement Object
 (
 [DocSum] => SimpleXMLElement Object
    (
        [Id] => 22064119
        [Item] => Array
            (
                [0] => 2011 Dec
                [1] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [Name] => EPubDate
                                [Type] => Date
                            )

                    )

                [2] => Clin Nucl Med
                [3] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [Name] => AuthorList
                                [Type] => List
                            )

                        [Item] => Array
                            (
                                [0] => Jackson TA
                                [1] => Choong KW
                                [2] => Eng JA
                                [3] => McAneny D
                                [4] => Subramaniam RM
                                [5] => Knapp PE
                            )

                    )

                [4] => Knapp PE
                [5] => F-18 FDG PET/CT Imaging of Endogenous Cushing Syndrome.
                [6] => 36
                [7] => 12
                [8] => e231-2
                [9] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [Name] => LangList
                                [Type] => List
                            )

                        [Item] => English
                    )

                [10] => 7611109
                [11] => 0363-9762
                [12] => 1536-0229
                [13] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [Name] => PubTypeList
                                [Type] => List
                            )

                        [Item] => Journal Article
                    )

                [14] => PubMed - in process
                [15] => ppublish
                [16] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [Name] => ArticleIds
                                [Type] => List
                            )

                        [Item] => Array
                            (
                                [0] => 10.1097/RLU.0b013e3182336360
                                [1] => 00003072-201112000-00044
                                [2] => 22064119
                                [3] => 22064119
                                [4] => 22064119
                            )

                    )

                [17] => 10.1097/RLU.0b013e3182336360
                [18] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [Name] => History
                                [Type] => List
                            )

                        [Item] => Array
                            (
                                [0] => 2011/11/09 06:00
                                [1] => 2011/11/09 06:00
                                [2] => 2011/11/09 06:00
                            )

                    )

                [19] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [Name] => References
                                [Type] => List
                            )

                    )

                [20] => 1
                [21] => 0
                [22] => Clinical nuclear medicine
                [23] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [Name] => ELocationID
                                [Type] => String
                            )

                    )

                [24] => 2011 Dec;36(12):e231-2
            )

    )

 )

1 个答案:

答案 0 :(得分:1)

您可以在对象上运行XPath,如下所示:$xml->xpath('/DocSum/Item/3/Item');