MS的xpath和w3c的不一样??

fason 2004-08-06 01:49:22
<script>
var d = new ActiveXObject("Microsoft.XMLDOM");
d.loadXML("<root><Item text=\"0\"/><Item text=\"1\"/></root>");
alert(d.selectSingleNode("/root/Item[1]").getAttribute("text"));
</script>

mozilla下的/root/Item[1]是第一个Item,这与w3c的是一致的,ms的怎么是返回第二个Item??

...全文
122 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
sinolge 2004-08-19
  • 打赏
  • 举报
回复
up
dsclub 2004-08-19
  • 打赏
  • 举报
回复
阿信真的强啊
超级大笨狼 2004-08-11
  • 打赏
  • 举报
回复
<html>
<head>
<style>
table
{
border-collapse: collapse;
border-width: 4;
border-style: double;
border-color:#15336F;
font-size:12px;
}
body
{
font-size:12px;
}
div
{
width:100%;
height:9;
border-style:solid;
border-width:1;
border-color:#eeeeee;
vertical-align:top;
font-size:12;
cursor:hand;
}
</style>
<title>笨狼树状节点查看器</title>
</head>
<body>
<INPUT type="file" id=file1 name=file1>请输入xml文件路径
<INPUT type="button" value="确定" onclick = "vbs:analyse ">
<SELECT id="select1" onchange="vbs:analyse">
<OPTION value="nodeName" >显示标签</OPTION>
<OPTION value="text" >显示文字</OPTION>
<OPTION value="attribute" >显示属性</OPTION>

<OPTION value="XPath" >显示XPath</OPTION>
</SELECT>
<DIV id="oList" style="padding-left:0"></DIV>

</body>
<script language="vbScript" >
'**************************************
'****作者: 超级大笨狼 superdullwolf****
'**************************************

public dic,favour,anything ,doc

set doc = CreateObject("Microsoft.XMLDOM")
doc.async=False
sub analyse()
dim myTR
favour = select1.value
removeDIV
if not doc.load(file1.value) then
alert "文件加载失败,请检查文件是否存在!"
else
Set rootNode = doc.DocumentElement
set rootDIV = document.createElement("DIV")

oList.setAttribute "XPath",rootNode.nodeName
oList.setAttribute "parsed",false
appendDIV oList,rootNode


end if
end sub

sub appendDIV(myDIV,myNode)

dim myChild ,newDIV,ChildID,thisID
ChildID = 0

for each myChild in myNode.childNodes
set newDIV = document.createElement("DIV")
myDIV.appendChild newDIV

addPx newDIV, myDIV,10

if ChildID>0 then
if myChild.previousSibling.nodeName <> myChild.nodeName then
ChildID =0

end if
end if

newDIV.setAttribute "XPath",getXPath(myDIV,myChild.nodeName,ChildID)
newDIV.setAttribute "parsed",false

newDIV.title = newDIV.getAttribute("XPath")
newDIV.innerText = getText(myChild,newDIV)

if myChild.childNodes.length>0 then
if myChild.nodeName <> "#text" then
newDIV.attachEvent "onclick",GetRef("attachOnclick")
end if
end if
ChildID = ChildID + 1




next
myDIV.setAttribute "parsed",true
end sub

function getXPath(myDIV,name,index)
getXPath = myDIV.getAttribute("XPath") & "/" & name & "[" & index & "]"

end function

sub removeDIV()
dim oldDIV
for each oldDIV in oList.childNodes
oldDIV.removeNode(true)
next
end sub

sub attachOnclick()
dim obj ,nodeXPath
set obj=window.event.srcElement
nodeXPath = obj.getAttribute("XPath")
if instr(nodeXPath,"#") then
window.event.cancelBubble = true
exit sub
end if
if not obj.getAttribute("parsed")= true then
appendDIV obj ,doc.selectSingleNode(nodeXPath)
end if
window.event.cancelBubble = true

end sub

function getText(myNode,oDIV)
dim myAttribute
getText = ""
select case favour
case "text"
if not isnull(myNode.text) then
getText = myNode.text
else
getText = "空文字"
end if
case "nodeName"
getText = myNode.nodeName
case "attribute"
if myNode.nodeName <>"#text" then
for each myAttribute in myNode.attributes
getText =getText & myAttribute.name
getText = getText & "=" & chr(34)
getText = getText & myAttribute.value & chr(34) & " "
next
getText = trim(getText)
end if


case "XPath"
getText = oDIV.title
end select
if trim(getText) ="" then getText ="空"
end function

sub addPx(newDIV,oldDIV,num)
dim re,myString
set re = new RegExp
re.Global = true
re.Pattern = "[^\d]*"
myString = re.Replace(oldDIV.style.paddingLeft, "")
if myString ="" then myString = "0"
myString = (cint(myString) + num ) & "px"
newDIV.style.paddingLeft = myString
set re = nothing
end sub
</script>
</html>
fason 2004-08-09
  • 打赏
  • 举报
回复
有一个方法...
objDOM.setProperty("SelectionLanguage","XPath");

解决
W3China 2004-08-07
  • 打赏
  • 举报
回复
MS一向不服从W3C的,自己想怎么做就怎么做。。

ice_berg16 2004-08-07
  • 打赏
  • 举报
回复
啊信怎么改名了
fason 2004-08-06
  • 打赏
  • 举报
回复
那怎么兼容啊...
fason 2004-08-06
  • 打赏
  • 举报
回复
MSXML3才符合啊~~~~,晕掉了....
孟子E章 2004-08-06
  • 打赏
  • 举报
回复
ms xml3 sp4已经符合w3c的标准了

The MSXML 3.0 release supports every existing XSL Transformations (XSLT) and XML Path Language (XPath) feature included in the current standards.
fason 2004-08-06
  • 打赏
  • 举报
回复
up

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧