XML DOM textContent 属性
定义和用法
textContent 属性可设置或返回节点及其后代的文本内容。
关于设置,任何子节点可被删除,并被一个单独的文本节点所替换,所替换的内容是此属性所设置的字符串。
语法:
nodeObject.textContent
example
In all examples, we will use the XML file books.xml, and JavaScript functions loadXMLDoc().
The following code snippet can return the text content of the <book> element:
xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
document.write(x.item(i).textContent
);
document.write("<br />");
}
Output:
Everyday Italian Giada De Laurentiis 2005 30.00 Harry Potter J K. Rowling 2005 29.99 XQuery Kick Start James McGovern Per Bothner Kurt Cagle James Linn Vaidyanathan Nagarajan 2003 49.99 Learning XML Erik T. Ray 2003 39.95
TIY
- textContent - Get the text content of a node(Not supported by IE)
- textContent - Set the text content of a node(Not supported by IE)