<SCRIPT LANGUAGE="JavaScript"> <!-- var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0"); var currNode; xmlDoc.async = false; xmlDoc.async = false; xmlDoc.loadXML("<TABLENAME> 你好你阿三 大法 司法等四 </TABLENAME>"); currNode = xmlDoc.documentElement;
var s = currNode.xml; var r = /\<([^\>\s]*?)[^\>]*?\>([^\<]*?)\<\/\1\>/ var b = s.replace(r,"$2"); alert(b);//--> </SCRIPT>
我们必须用ie 5.0 这个对象不行。"Msxml2.DOMDocument.4.0" 把它换成"Microsoft.XMLDOM"对象。 显示错误信息:错误的数量词。 非常谢谢你。 我现在用这个解决了 var r = /^\<TABLENAME\>/; var b = retval.replace(r,""); r = /\<\/TABLENAME\>$/; b = b.replace(r,""); 现看了一下正则表达式的书,我写的很蠢。 楼上的高人还有好的办法么? 再一次的谢谢你。
<html> <head> </head> <body> <script language="JavaScript"> var orderDoc = new ActiveXObject("Microsoft.XMLDOM"); orderDoc.loadXML("<TABLEINF> <TABLENAME> 你好你阿三 大法 司法等四 </TABLENAME></TABLEINF>"); function getNodeG(doc, xpath) { var retval = ""; var r = /\<([^\>\s]*?)[^\>]*?\>([^\<]*?)\<\/\1\>/ var value = doc.selectSingleNode(xpath); if (value) retval = value.xml.replace(r,"$2");; return retval; } function displayXML(){ var tt = getNodeG(orderDoc, "/TABLEINF/TABLENAME"); alert(tt); } </script> <input type="button" value="显示XML信息" onclick="displayXML()"> </body> </html>
或者如inelm(木野狐) 所说,用CDATAtext Property Represents the text content of the node or the concatenated text representing the node and its descendants.Res String. The property is read/write. When concatenated, the text represents the contents of text or CDATA nodes. All concatenated text nodes are normalized according to xml:space attributes and the value of the preserveWhiteSpace switch. Concatenated CDATA text is not normalized. (Child nodes that contain NODE_COMMENT and NODE_PROCESSING_INSTRUCTION nodes are not concatenated.)Retrieves and sets the string representing the text contents of this node or the concatenated text representing this node and its descendants.
<!--
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var currNode;
xmlDoc.async = false;
xmlDoc.async = false;
xmlDoc.loadXML("<TABLENAME> 你好你阿三 大法 司法等四 </TABLENAME>");
currNode = xmlDoc.documentElement;
var s = currNode.xml; var r = /\<([^\>\s]*?)[^\>]*?\>([^\<]*?)\<\/\1\>/ var b = s.replace(r,"$2"); alert(b);//-->
</SCRIPT>
把它换成"Microsoft.XMLDOM"对象。
显示错误信息:错误的数量词。
非常谢谢你。
我现在用这个解决了
var r = /^\<TABLENAME\>/;
var b = retval.replace(r,"");
r = /\<\/TABLENAME\>$/;
b = b.replace(r,"");
现看了一下正则表达式的书,我写的很蠢。
楼上的高人还有好的办法么?
再一次的谢谢你。
<head>
</head>
<body>
<script language="JavaScript">
var orderDoc = new ActiveXObject("Microsoft.XMLDOM");
orderDoc.loadXML("<TABLEINF> <TABLENAME> 你好你阿三 大法 司法等四 </TABLENAME></TABLEINF>");
function getNodeG(doc, xpath) {
var retval = "";
var r = /\<([^\>\s]*?)[^\>]*?\>([^\<]*?)\<\/\1\>/
var value = doc.selectSingleNode(xpath);
if (value)
retval = value.xml.replace(r,"$2");; return retval;
}
function displayXML(){
var tt = getNodeG(orderDoc, "/TABLEINF/TABLENAME");
alert(tt);
}
</script>
<input type="button" value="显示XML信息" onclick="displayXML()">
</body>
</html>
<TABLEINF>
<TABLENAME xml:space="preserve"> 你好你阿三 大法 司法等四 </TABLENAME>
</TABLEINF>
Represents the text content of the node or the concatenated text representing the node and its descendants.Res
String. The property is read/write. When concatenated, the text represents the contents of text or CDATA nodes. All concatenated text nodes are normalized according to xml:space attributes and the value of the preserveWhiteSpace switch. Concatenated CDATA text is not normalized. (Child nodes that contain NODE_COMMENT and NODE_PROCESSING_INSTRUCTION nodes are not concatenated.)Retrieves and sets the string representing the text contents of this node or the concatenated text representing this node and its descendants.
to vivianfdlpw() , ttyp(@http://www.cnblogs.com/ttyp/) , inelm(木野狐) 有这方面的资料么
能不能给我发个消息。
或发到[email protected]
结了。
<-------好好学习,天天向上------>