高手在那里!关于xmlhttp.responseXML返回问题,我的是IE8,不知道如何得到xml里面的值

高手在那里!关于xmlhttp.responseXML返回问题,我的是IE8,不知道如何得到xml里面的值,第1张

这样就可以了:

<html>

<head>

<title></title>

<script type="text/javascript">

var xml = '<xml version="10" encoding="utf-8"><root><text>fda</text><text>ffff</text><text>r32&f23r</text></root>';

var dom = new ActiveXObject("MSXML2DOMDocument40");

domloadXML(xml);

var nodes = domselectNodes("/root/text");

for (var i = 0; i < nodeslength; i++) {

alert(nodes[i]text);

}

</script>

</head>

<body>

</body>

</html>

注意xml里面的&要换成&不然xml是不正确哈。

我最近也做这个事情,我不限制的服务,然后自动识别,呼叫麻烦了。

点击一个链接,转到jsp页面,运行一个类似的计划,在jsp中显示的结果。

参考: >

可以把我以前做的解析和生成XML的代码给你看一下,你可以参考参考:

代码如下:

public static class PaperXMLManager

{

/// <summary>

/// 输入试卷信息 生成 试卷内容xml字符串

/// </summary>

public static void GetExamPaperXMLStr(XmlDocument objXmlDoc, EntityArrayList<Item> items, string paperCode, ExamPolicy examPolicy)

{

XmlNode root = objXmlDocSelectSingleNode("ExamPaper");

XmlNode node;

XmlElement subnode;

if (root == null)

{

root = objXmlDocCreateElement("ExamPaper"); //创建一个<ExamPaper>根节点

objXmlDocAppendChild(root);

}

else

{

root = objXmlDocSelectSingleNode("ExamPaper");//查找<ExamPaper>根节点

}

foreach (Item it in items)

{

node = objXmlDocCreateElement("Item");

subnode = objXmlDocCreateElement("Code");

subnodeInnerText = itCode;

nodeAppendChild(subnode);

subnode = objXmlDocCreateElement("Ver");

subnodeInnerText = itVerToString();

nodeAppendChild(subnode);

subnode = objXmlDocCreateElement("Score");

subnodeInnerText = examPolicyScorePerItemToString();

nodeAppendChild(subnode);

subnode = objXmlDocCreateElement("EPCode");

subnodeInnerText = examPolicyEPCode;

nodeAppendChild(subnode);

rootAppendChild(node);

}

}

/// <summary>

/// 获取Xml格式字符串的内容

/// </summary>

/// <param name="str">Xml格式字符串</param>

/// <returns>Xml内容的DataTable</returns>

public static DataTable GetItemTable(string str)

{

XmlDocument objXmlDoc = GetXmlDocByStr(str);

DataTable dt = new DataTable();

dtColumnsAdd("Code");

dtColumnsAdd("Ver");

dtColumnsAdd("Score");

dtColumnsAdd("EPCode");

XmlNodeList nodes = objXmlDocGetElementsByTagName("Item");

foreach (XmlNode xmlNode in nodes)

{

DataRow dr = dtNewRow();

for (int j = 0; j < xmlNodeChildNodesCount; j++)

{

dr[j] = xmlNodeChildNodes[j]InnerText;

}

dtRowsAdd(dr);

}

return dt;

}

/// <summary>

/// 获取Xml的内容

/// </summary>

/// <param name="objXmlDoc">Xml文件</param>

/// <returns>Xml内容的DataTable</returns>

public static DataTable GetItemTable(XmlDocument objXmlDoc)

{

DataSet ds = new DataSet();

StringReader read = new StringReader(objXmlDocSelectSingleNode("ExamPaper")OuterXml);

dsReadXml(read);

DataTable tblRes = new DataTable();

tblRes = dsTables[0];

return tblRes;

}

/// <summary>

/// 从指定格式的字符串中加载Xml文档

/// </summary>

/// <param name="str">xml格式的字符串</param>

/// <returns>xml文档对象</returns>

public static XmlDocument GetXmlDocByStr(string str)

{

XmlDocument dom = new XmlDocument();

domLoadXml(str);

return dom;

}

/// <summary>

/// 在当前XML中找到指定值的节点

/// </summary>

/// <param name="objXmlDoc">xml</param>

/// <param name="itemCode">节点内容</param>

/// <returns>节点</returns>

public static XmlNode GetNode(XmlDocument objXmlDoc, string itemCode)

{

XmlNode Nodelist = objXmlDocSelectSingleNode("ExamPaper");

foreach (XmlNode node in NodelistSelectNodes("Item"))

{

if (nodeSelectSingleNode("Code")InnerText == itemCode)

{

return node;

}

}

return null;

}

/// <summary>

/// 替换掉XML文件中值为oldItemCode的节点下子节点的值

/// </summary>

/// <param name="objXmlDoc">xml对象</param>

/// <param name="oldItemCode">指定节点的值</param>

/// <param name="code">试题编码</param>

/// <param name="ver">试题版本</param>

/// <param name="score">试题分值</param>

/// <param name="epcode">策略编号</param>

/// <returns>替换后的XML对象</returns>

public static XmlDocument ReplaceItem(XmlDocument objXmlDoc, string oldItemCode, string code, string ver, string score, string epcode)

{

try

{

XmlNode node = GetNode(objXmlDoc, oldItemCode);

nodeSelectSingleNode("Code")InnerText = code;

nodeSelectSingleNode("Ver")InnerText = ver;

nodeSelectSingleNode("Score")InnerText = score;

nodeSelectSingleNode("EPCode")InnerText = epcode;

return objXmlDoc;

}

catch

{

return objXmlDoc;

}

}

/// <summary>

/// 删除选定节点

/// </summary>

/// <param name="nodeText">节点内容</param>

/// <param name="xmlStr">xml字符串</param>

/// <returns>删除后XmlDocument对象</returns>

public static XmlDocument DelNode(string nodeText, string xmlStr)

{

XmlDocument xmlDoc = GetXmlDocByStr(xmlStr);

XmlNode node = GetNode(xmlDoc, nodeText);

if (xmlDoc != null)

{

XmlNode Nodelist = xmlDocSelectSingleNode("ExamPaper");

NodelistRemoveChild(node);

return xmlDoc;

}

return xmlDoc;

}

}

以上的方法多一些~你也可以参考我下面的代码~知道XML节点格式后直接解析为一个DataTable,这样你知道内容了就可以显示了:

代码如下:

/// <summary>

/// 从指定格式的字符串中加载Xml文档

/// </summary>

/// <param name="str">xml格式的字符串</param>

/// <returns>xml文档对象</returns>

public static XmlDocument GetXmlDocByStr(string str)

{

XmlDocument dom = new XmlDocument();

domLoadXml(str);

return dom;

}

/// <summary>

/// 获取Xml的内容

/// </summary>

/// <param name="objXmlDoc">Xml文件</param>

/// <returns>Xml内容的DataTable</returns>

public static DataTable GetItemTable(string str)

{

XmlDocument objXmlDoc = GetXmlDocByStr(str);

DataTable dt = new DataTable();

dtColumnsAdd("Code");

dtColumnsAdd("EpCode");

dtColumnsAdd("Ver");

dtColumnsAdd("Score");

dtColumnsAdd("UserScore");

dtColumnsAdd("RightAnswer");

dtColumnsAdd("UserAnswer");

XmlNodeList nodes = objXmlDocGetElementsByTagName("Item");

foreach (XmlNode xmlNode in nodes)

{

DataRow dr = dtNewRow();

for (int j = 0; j < xmlNodeChildNodesCount; j++)

{

dr[j] = xmlNodeChildNodes[j]InnerText;

}

dtRowsAdd(dr);

}

return dt;

}

}

以上就是关于高手在那里!关于xmlhttp.responseXML返回问题,我的是IE8,不知道如何得到xml里面的值全部的内容,包括:高手在那里!关于xmlhttp.responseXML返回问题,我的是IE8,不知道如何得到xml里面的值、asp如何抓取网页内容、解析Http接口返回的xml数据问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9822064.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存