解析xml到mysql
我有一个 XML 提要,我需要从中解析其中的一些并将其存储到 MySQL 表中,但我面临着一种新的 XML(我不擅长这个) 以下是我使用 simplexml_load_file
从此地址打开的 XML: 这是一份 pubmed 期刊出版物我需要存储作者列表和其他一些内容,但有一个关于如何访问它的提示,我可以管理。 多谢
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
)
)
)
I have a XML feed from which I need to parse some of it and store it into MySQL table, but I'm facing a new kind of XML (I'm not good at this)
Here is the XML I'm getting which i'm opening using simplexml_load_file
from this address:
It's a pubmed journal publication I need to store authorlist and some other, but with a hint on how to access it I can manage.
Thanks a lot
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
)
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样在对象上运行 XPath:
$xml->xpath('/DocSum/Item/3/Item');
You can run an XPath on the object like this:
$xml->xpath('/DocSum/Item/3/Item');