首页 > 应用开发 > IT综合 > XML文件源码察看器(六) (转)
case 9: 'Document 节点 -- “根”节点。不需要显示,只需显示子节点XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" />
'遍历节点的子节点就是这样写地 : ) ,so easy
intCount = nodNode.childNodes.length
if intCount > 0 then
for intNode = 0 to intCount-1
strNodes =strNodes & renderChildNodes(nodNode.childNodes(intNode), intLevel + 1)
next
end if
case else:'普通节点
strNodes=strNodes & getIndent(intLevel)& "<" ' 蓝色 <
strNodes=strNodes & ""& nodNode.nodeName & " " ' 褐色 node name
'显示 属性
set nodAttrList = nodNode.attributes'得到属性节点集(collection -- 我最喜欢的数据类型之一)先
intCount = nodAttrList.length 'collection 之 length ,方便吧? :)
if intCount > 0 then
for intAttr = 0 to intCount-1
'红色 属性名,蓝色 引号
strNodes =strNodes & ""+nodAttrList(intAttr).nodeName + "=""" & nodAttrList(intAttr).nodeValue & """ "
next
end if
'处理当前节点的子节点
intCount = nodNode.childNodes.length
if intCount > 0 then'如果有子节点
strNodes=strNodes & ">
" '属性显示完 ,用“ 〉“闭合 Tag先
' 对每个子节点递归调用 renderChildNodes
for intNode = 0 to intCount-1
strNodes = strNodes & renderChildNodes(nodNode.childNodes(intNode), intLevel + 1)
next
'显示关闭标记
strNodes= strNodes & getIndent(intLevel) & "</"+nodNode.nodeName & ">
"
else
strNodes = strNodes & "/>
" '没有子节点, 显示 “ /〉“
end if
end select
renderChildNodes = strNodes
end function
'给注释节点着色
function renderComment(nodNode,intLevel)
dim strNodes,intCount,intNode
strNodes = ""
intCount = 0
intNode = 0
dim nodAttrList
strNodes=strNodes & getIndent(intLevel)& "<!-- "
strNodes= strNodes & nodNode.nodeValue
strNodes=strNodes &" -->
"
renderComment = strNodes
end function
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-981934/ ,如需转载,请注明出处,否则将追究法律责任。