2010-04-05 104 views
2

問候,將XML轉換爲TCL對象

我是新來的TCL腳本,我有一個非常非常基本的xml文件,我需要將信息從tcl導入。 XML文檔結構的

例子:

<object> 
    <type>Hardware</type> 
    <name>System Name</name> 
    <description>Basic Description of System.</description> 
    <attributes> 
     <vendor>Dell</vendor> 
     <contract>MM/DD/YY</contract> 
     <supportExpiration>MM/DD/YY</supportExpiration> 
     <location>Building 123</location> 
     <serial>xxx-xxx-xxxx</serial> 
     <mac>some-mac-address</mac> 
    </attributes> 
</object> 

等...

我見過一些所謂TCLXML,但我不知道這是最好的途徑,甚至如何創建包使用它..

任何幫助將不勝感激。

回答

2

我可以推薦使用tdom包進行XML解析,特別是它包含與XPath的良好集成,因此很容易從數據中提取內容。它也很快。

如果您使用的是ActiveTcl,那麼它已經是其中的一部分(儘管您可能需要執行teacup update才能將其從存儲庫中引入)。

+0

謝謝,這是有幫助的。我試過包需要tdom,但沒有找到,所以我從網站上下載了tDom。我如何設置路徑來查找這個新下載的包? – pws5068 2010-04-05 20:35:10

+1

您安裝它的目錄(您是否構建並安裝它,是的?) - *或*其父目錄 - 需要位於Tcl的'auto_path'列表中。 – 2010-04-05 20:39:04

+0

我下載了win32 DLL的 – pws5068 2010-04-05 20:45:19