如何解析XML以获取一个标签并在其中保存另一个标签 [英] How parse XML to get one tag and save another tag inside

查看:131
本文介绍了如何解析XML以获取一个标签并在其中保存另一个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP5.3的 DOM
扩展名可以使用< title>标记来解析某些xml文档,例如:

I use DOM extension of PHP5.3 to parse some xml document with <title> tag like this:

< title>某些文本< word>关键字< / word>一些文本< / title>

我想从标签< title>中获得带有特定标签的结果(我想知道关键字,这就是为什么我要保存标签<标记< title>内的word>)。在这种情况下,结果必须是这样的:

I want get result from tag <title> with certain tags inside it (i want know keywords that's why i want save tag <word> inside tag <title>). Result in this case must be something like this:

某些文本[word]关键字[/ word]一些文本

我执行一些代码:

$ title = $ doc-> getElementsByTagName('title')- > item(0)-> nodeValue;

$ title必须包含某些结果。但是我只能看到其中没有任何标签的文本,而且现在也不知道关键字在哪里。

$title must contain some result. But I get only text without any tags inside it and I don't know now where keywords is.

某些文本关键字某些文本

我不知道如何保存标签< word>!
如何从DOM扩展名中获得一些文本[word]关键字[/ word]一些文本等结果?

I don't know how to save tag <word>! How could I get result like some text [word]keyword[/word] some text from DOM extension?

感谢

推荐答案

如果您需要所有内容+标记本身,则总是 saveXML

If you want everything + the tags themselves, there's always saveXML:

http ://us3.php.net/manual/zh-CN/domdocument.savexml.php

您传递所需的节点,它会返回一个字符串,尽管会包含< title> 起始和结束标签。此外,它还将包括属性。

You pass the node you want and it gives you a string back, though the <title> start and end tags will be included. Also it will include attributes as well.

这篇关于如何解析XML以获取一个标签并在其中保存另一个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆