admin管理员组文章数量:1323342
I simply need to extract some info between two tags, in this case, <title>
For example:
...
<title>I Need This!</title>
...
And I simply need to be able to get the information between the tags. I was thinking using split()
, however, I haven't been able to figure out how to cut all data before and after, and just catch the stuff in the title tags. As you can tell, I'm a beginner with text formatting. Thanks!
EDIT: An example of the type of file I'm looking through is here: ://youtu.be/_OBlgSz8sSMg?v=2
I'm simply trying to take what's in the title tags to get the title of the video.
I simply need to extract some info between two tags, in this case, <title>
For example:
...
<title>I Need This!</title>
...
And I simply need to be able to get the information between the tags. I was thinking using split()
, however, I haven't been able to figure out how to cut all data before and after, and just catch the stuff in the title tags. As you can tell, I'm a beginner with text formatting. Thanks!
EDIT: An example of the type of file I'm looking through is here: https://gdata.youtube./feeds/api/videos/http://youtu.be/_OBlgSz8sSMg?v=2
I'm simply trying to take what's in the title tags to get the title of the video.
Share Improve this question edited Jul 23, 2012 at 17:32 Jtaylorapps asked Jul 23, 2012 at 17:22 JtaylorappsJtaylorapps 5,7809 gold badges42 silver badges57 bronze badges 3- Are you parsing HTML text or do you want to pull the title from the current page? If the former, I would remend a simple regular expression to strip away the HTML tags. – Cᴏʀʏ Commented Jul 23, 2012 at 17:24
- Use an XML parser. Or do you have something specific? – Bergi Commented Jul 23, 2012 at 17:24
- It's specific. I get a value returned, which is a huge text (the XML code). Then I parse the text, searching for the title tags, and then I collect the value – Jtaylorapps Commented Jul 23, 2012 at 17:27
2 Answers
Reset to default 7var text = '<title>I Need This!</title>',
match = text.match(/<title>([^<]*)<\/title>/),
youGotThis = match[1];
Here's the fiddle: http://jsfiddle/RPbSE/
DOM works on XML just as well as on HTML, so a simple
var titleNodeList = yourXMLDocument.getElementsByTagname('title');
var firstTitle = titleNodeList[0];
var titleTextNode = firstTitle.firstChild;
alert(titleTextNode);
should do.
本文标签: javascriptJSRead Data Between XML TagsStack Overflow
版权声明:本文标题:javascript - JS - Read Data Between XML Tags - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742134302a2422301.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论