[英]How can we run an xml file using TCL Script?
I have an XML
file located on a Unix server. 我在Unix服务器上有一个
XML
文件。 How can I run that XML
file using a Tcl
script? 如何使用
Tcl
脚本运行该XML
文件?
If you are looking for a simple way to parse (if that's what you mean by run) XML, consider tdom package. 如果您正在寻找一种简单的XML解析方法(如果这就是运行的意思),请考虑使用tdom包。
Reference: http://wiki.tcl.tk/8984 参考: http : //wiki.tcl.tk/8984
Here's a file foo.xml with the following content: 这是一个具有以下内容的文件foo.xml:
<my_root>
<my_child1>
<my_subchild1 foo="bar">bat</my_subchild1>
</my_child1>
</my_root>
Read the xml data into a variable (not the best way if the XML content is large): 将xml数据读取到变量中(如果XML内容较大,则不是最佳方法):
%
% set fd [open foo.xml]
file3
% set xml [read $fd]
<my_root>
<my_child1>
<my_subchild1 foo="bar">bat</my_subchild1>
</my_child1>
</my_root>
% close $fd
%
Now parse it: 现在解析它:
% package require tdom
0.8.3
%
% set documentHandle [dom parse $xml]
domDoc0x2510320
% set root [$documentHandle documentElement]
domNode0x2546d90
% $root asXML
<my_root>
<my_child1>
<my_subchild1 foo="bar">bat</my_subchild1>
</my_child1>
</my_root>
% set child1 [$root firstChild]
domNode0x16dcec0
% $child1 asXML
<my_child1>
<my_subchild1 foo="bar">bat</my_subchild1>
</my_child1>
% set tmp [$root selectNodes //my_subchild1]
domNode0x16dd630
% $tmp asXML
<my_subchild1 foo="bar">bat</my_subchild1>
% $tmp getAttribute foo
bar
% $tmp text
bat
%
Here's the list of supported command with a parsed xml node: 这是带有已解析的xml节点的受支持命令的列表:
% $tmp
Usage nodeObj <method> <args>, where method can be:
nodeType
nodeName
nodeValue ?newValue?
hasChildNodes
childNodes
childNodesLive
parentNode
firstChild ?nodeObjVar?
lastChild ?nodeObjVar?
nextSibling ?nodeObjVar?
previousSibling ?nodeObjVar?
hasAttribute attrName
getAttribute attrName ?defaultValue?
setAttribute attrName value ?attrName value ...?
removeAttribute attrName
hasAttributeNS uri localName
getAttributeNS uri localName ?defaultValue?
setAttributeNS uri attrName value ?attrName value ...?
removeAttributeNS uri attrName
attributes ?attrNamePattern?
appendChild new
insertBefore new ref
replaceChild new old
removeChild child
cloneNode ?-deep?
ownerDocument
getElementsByTagName name
getElementsByTagNameNS uri localname
getElementById id
find attrName attrValue ?nodeObjVar?
child number|all ?type? ?attrName attrValue?
descendant number|all ?type? ?attrName attrValue?
ancestor number|all ?type? ?attrName attrValue?
fsibling number|all ?type? ?attrName attrValue?
psibling number|all ?type? ?attrName attrValue?
root ?nodeObjVar?
target
data
text
prefix
namespaceURI
getBaseURI
baseURI ?URI?
localName
delete
getLine
getColumn
@<attrName> ?defaultValue?
asList
asXML ?-indent <none,0..8>? ?-channel <channel>? ?-escapeNonASCII? ?-escapeAllQuot? ?-doctypeDeclaration <boolean>?
asHTML ?-channel <channelId>? ?-escapeNonASCII? ?-htmlEntities?
asText
appendFromList nestedList
appendFromScript script
insertBeforeFromScript script ref
appendXML xmlString
selectNodes ?-namespaces prefixUriList? ?-cache <boolean>? xpathQuery ?typeVar?
toXPath
disableOutputEscaping ?boolean?
precedes node
normalize ?-forXPath?
xslt ?-parameters parameterList? <xsltDocNode>
readlock
writelock
%
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.