Domanda

In TCL, se si utilizza il pacchetto di DOM (disponibile nella distribuzione ActiveState) è possibile creare un xml.

set xmlDoc [::dom::create]
set root [::dom::document createElement $xmlDoc "trafficStatistics"]

set statElement [::dom::document createElement $root "Tx_Frames"]
::dom::element setAttribute $statElement "type" "numericlist"
::dom::element setAttribute $statElement "displayName" "Tx Frames"

puts [::dom::serialize $xmlDoc -indent true]

la creazione di questa semplice xml:

<result>
    <trafficStatistics type="structure">
        <Tx_Frames type="numericlist" displayName="Tx Frames"></Tx_Frames>
    </trafficStatistics>
</result>

Come posso aggiungere alcuni dati all'elemento Tx_Frames?

<Tx_Frames type="numericlist" displayName="Tx Frames">some data</Tx_Frames>

Si noti che il pacchetto dom è in realtà un wrapper sopra libxml2

È stato utile?

Soluzione

Credo che si desidera che il comando di ::dom::document createTextNode. Ad esempio:

::dom::document createTextNode $statElement "some data"

Quando aggiungo questo comando per lo script di esempio:

set xmlDoc [::dom::create]
set root [::dom::document createElement $xmlDoc "trafficStatistics"]

set statElement [::dom::document createElement $root "Tx_Frames"]
::dom::element setAttribute $statElement "type" "numericlist"
::dom::element setAttribute $statElement "displayName" "Tx Frames"
::dom::document createTextNode $statElement "some data"

Si produce questo XML:

<trafficStatistics>
  <Tx_Frames type="numericlist" displayName="Tx Frames">some data</Tx_Frames>
</trafficStatistics>

È possibile trovare la documentazione per il pacchetto dom qui:

http://docs.activestate.com/activetcl/8.5/tcldom /index.html

Speranza che aiuta,

Eric Melski

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top