使用php将.xml的部分导入sql数据库
我正在尝试使用php将.xml文件的几个部分导入mysql数据库。我要导入的零件用特定关键字标记。是否可以在导入之前指定特定关键字的导入或研究 这只是xml文件的一小部分摘录:使用php将.xml的部分导入sql数据库,php,mysql,xml,import,keyword,Php,Mysql,Xml,Import,Keyword,我正在尝试使用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<
<?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>
//这是我要导入的部分:
第1天
第1课
8.
主题1
主题1
第一类
Hr/“geaendert”是关键字
教师1
1号房间
//这是我不想导入的信息(采用正常格式):
白天
课程
36
主题
主题
班
老师
老师
房间
关键字有不同的变体(如:LegeEndert、RageEndert、FageEndert)
我已经有了导入整个.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?
)