[英]Trouble retrieving inner text from XML node using JavaScript
I'm reading an XML document using JavaScript & jQuery, and need to extract some text from inside a node to save into an array. 我正在使用JavaScript和jQuery读取XML文档,需要从节点内部提取一些文本以保存到数组中。 The structure of the XML is as such:
XML的结构如下:
<C>
<I>
<TEXTFORMAT>
<P>
<FONT>Here's the text I want</FONT>
</P>
</TEXTFORMAT>
</I>
</C>
Everything I've tried so far returns nothing so I must be incorrectly referencing the contents of the FONT tag. 到目前为止我尝试过的所有东西都没有返回,所以我必须错误地引用FONT标签的内容。
What XML path should I be using? 我应该使用什么XML路径?
This will give you an array of the content of the FONT
nodes. 这将为您提供
FONT
节点内容的数组。
var array = $(xml).find('FONT').map(function() {
return $(this).text();
}).get();
Relevant jQuery docs: 相关的jQuery文档:
.map()
- http://api.jquery.com/map/ .map()
- http://api.jquery.com/map/ .text()
- http://api.jquery.com/text/ .text()
- http://api.jquery.com/text/ .get()
- http://api.jquery.com/get/ .get()
- http://api.jquery.com/get/ .find()
- http://api.jquery.com/find/ .find()
- http://api.jquery.com/find/ function parseXml(xml)
{
//find every FONT element and store its value
$(xml).find("FONT").each(function()
{
// put this.text() into the array
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.