XMLReader 用作迭代器,因此您必须根据 xml 文档的各个标记来实现分组/提取逻辑。假设<row>
您的 xml 文件中有一个元素对应于单个插入,它可能看起来像这样:
$reader = new XMLReader();
$reader->open('/path/to/the/file.xml');
while ($reader->read()) {
if ($reader->name == "row" && $reader->nodeType == XMLReader::ELEMENT) {
// the cursor currently at <row> element
// hopefully one fragment will fit into memory and you can use simplexml for easy access
// alternatively try $reader->expand() for DOMNode of the same thing
$rowxml = simplexml_load_string('<'.'?xml version='1.0'?'.'>'.$reader->readOuterXML());
// build insert from the $rowxml object, run the query
}
}
$reader->close();