使用XMLReader搜索XML文件

时间:2014-01-29 19:51:21

标签: php xml dom search xmlreader

我有一个大的XML文件(大约20MB,但假设要增长),我有搜索表单,我可以输入搜索的关键字。我尝试使用DOMXPath::query找到我需要的东西。搜索正在遍历所有节点,如果找到匹配,则返回publication元素(请参阅下面的XML)。它工作正常,但如果我有10 000个出版物搜索持续4秒,这是非常缓慢的(我希望有数百万的出版物)。

XML文件:

  <publication>
    <identificators>
      <identificator type="isbn">978-1-101-61439-8</identificator>
    </identificators>
    <title>Secured foreground capacity</title>
    <abstract>Illo dignissimos nulla libero ut ut. Inventore voluptas mollitia et officia. In quidem inventore voluptatem quas maxime. Et similique aliquam et sunt nulla.
Quae molestiae dolor architecto dicta non. Quia illo quia tempore architecto pariatur quo commodi cumque. Cumque nemo qui sunt.
Corporis quia reprehenderit modi neque architecto perferendis eligendi. Eveniet nobis illum totam possimus modi assumenda. Quia sed hic sit sequi. Doloremque temporibus eaque velit sed enim.</abstract>
    <dates>
      <date type="release">18.09.1995</date>
      <date type="added">17.07.1991</date>
    </dates>
    <language>Bajan</language>
    <release-number>2</release-number>
    <publisher>Kub PLC</publisher>
    <filepath/to/file.pdf</file>
    <type>Note</type>
    <categories>
      <category>Health Professions</category>
      <category>Computer Science</category>
      <category>Agricultural and Biological Sciences</category>
      <category>Chemical Engineering</category>
      <category>Materials Science</category>
    </categories>
    <keywords>
      <keyword>quia</keyword>
      <keyword>placeat</keyword>
    </keywords>
    <authors>
      <main-author>Nannie Klocko</main-author>
      <co-authors>
        <co-author>Name Surname</co-author>
      </co-authors>
    </authors>
    <affiliation>
      <name>Rippin, Stehr and Ryan</name>
      <type>Organisation</type>
      <address>
        <street>Rath Corner</street>
        <city>San Nicolás de los Garza</city>
        <country/>
      </address>
    </affiliation>
  </publication>

所以我读到了XMLReader它的速度有多快等等,但我发现只有例子如何阅读整个文件,我需要知道我是否可以用它来加快搜索速度?如果是这样,你能提供一些简单的例子吗?

现在是我的XPath查询:

$xpath_query = "//publications/publication[contains(translate(., 'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 'abcdefghjiklmnopqrstuvwxyz'), '$search_keyword')]";

我可以在XMLReader中使用这样的东西吗?非常感谢您的每一个提示。

0 个答案:

没有答案