我正在尝试使用 php 将 .xml 文件的多个部分导入到 mysql 数据库中。我想要导入的部分标有特定的关键字。是否可以在导入前指定导入或研究某些关键字?
这只是 xml 文件的一小部分摘录:
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<kl_plan>
//this is the part I want to import:
<pl>
<pl_tag>day1</pl_tag>
<pl_stunde>lesson1</pl_stunde>
<pl_un>8</pl_un>
<pl_fach>subject1</pl_fach>
<pl_fachori>subject1</pl_fachori>
<pl_klasse>class1</pl_klasse>
<pl_lehrer legeaendert="legeaendert">Hr</pl_lehrer> //"geaendert" is the keyword
<pl_lehrerori>teacher1</pl_lehrerori>
<pl_raum>room1</pl_raum>
</pl>
//this is the information (with the normal format) I don't want to import:
<pl>
<pl_tag>day</pl_tag>
<pl_stunde>lesson</pl_stunde>
<pl_un>36</pl_un>
<pl_fach>subject</pl_fach>
<pl_fachori>subject</pl_fachori>
<pl_klasse>class</pl_klasse>
<pl_lehrer>teacher</pl_lehrer>
<pl_lehrerori>teacher</pl_lehrerori>
<pl_raum>room</pl_raum>
</pl>
</kl_plan>
关键字有不同的变体(例如:legeaendert、rageaendert、fageaendert)
我已经有一个导入整个 .xml 文件的代码。这并没有真正帮助我,因为 xml 中有太多不必要的信息。
最佳答案
嗨,你可以使用这个 simplexml_load_string — 将 XML 字符串解释为对象
使用小例子
$string = <<<XML
<?xml version='1.0'?>
<document>
<title>Forty What?</title>
<from>Joe</from>
<to>Jane</to>
<body>
I know that's the answer -- but what's the question?
</body>
</document>
XML;
$xml = simplexml_load_string($string);
print_r($xml);
示例将输出:
SimpleXMLElement Object
(
[title] => Forty What?
[from] => Joe
[to] => Jane
[body] =>
I know that's the answer -- but what's the question?
)
尝试一下,祝你好运......!!!
关于php - 使用 php 将 .xml 的一部分导入到 sql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35040365/