请教js解析xml问题 - Web 开发 / JavaScript
xml文档:books.xml
<bookstore>
<book category="children">
<title lang="en">sky</title>
<author></author>
</book>
</bookstore>
js文档:
<html>
<head>
<script type="text/javascript" src="/example/xdom/loadxmldoc.js"></script>
</head>
<body>
<script type="text/javascript">
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
txt=x.nodeValue;
document.write("title="+txt);
y=xmlDoc.getElementsByTagName("author")[0].childNodes[0];
txt1=y.nodeValue;
document.write("author="+txt1);
</script>
</body>
</html>
遍历节点的时候可以得到 title=sky
为何得不到author=
是不是因为author节点的值为空,我想得到author= 如何编写程序呢?
附:
loadxmldoc.js文档:
function loadXMLDoc(dname)
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
cat
相关问答:
Private Sub Command1_Click()
Dim MyString() As String
Open "a.xml" For Binary As #1 ' 打开刚创建的文件。
ReDim MyString(LOF(1) - 1)
Put #1, , MyRecord ' 读入所有字符到变量中 ......
我有一个类似的xml的 string,想通过遍历怎么个xml 输出我想要的element的值
xml 为:
<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
<RequestType>DISCOVER_XML_ME ......
如何用ATL窗体应用程序中用System.Xml遍历一个Xml文件
你说的是托管代码?
。
vc可用msxml
http://msdn.microsoft.com/en-us/library/ms767594(VS.85).aspx
MSXML4
//引入msxml4.dll &nbs ......
我用XmlDocument生成XML
XmlElement remarkNode = node.OwnerDocument.CreateElement("remark");
remark1Node.InnerXml = "";
如果InnerXml赋值不为空,则生成的标记是没问题的,比如:<r ......
用SAX解析XML中,使用这段代码
String feed="http://www.google.com/ig/api?weather="+strCity;
URL url = new URL(feed.replace(" ", "%20"));
......