2011-12-11 77 views
1

我有一个XML源,我需要解析它的一些并将其存储到MySQL表中,但我面临着一种新的XML(我不擅长这一点) 这是XML我得到,我打开使用simplexml_load_file从这个地址: It's a pubmed journal publication我需要存储authorlist和其他一些,但提示如何访问它,我可以管理。 非常感谢解析XML到MySQL

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

你可以像这样的对象上运行的XPath:$xml->xpath('/DocSum/Item/3/Item');

+0

不工作....... –

+0

它返回我阵列(),这一切..... –

+0

解决这个问题: $ xmlDOM = new DOMDocument(); $ xmlDOM-> loadXML($ xml); $ item = $ xmlDOM-> getElementsByTagName(“Item”); for($ i = 0; $ i <$item-> length; $ i ++){ $ nada [] = $ item-> item($ i) - > nodeValue; } $ todo = explode(“\ n”,$ nada [3]); 谢谢。 –