Re: parsing xml file contents



sreedhar wrote:
Hi All,

I am trying to write a script for parsing the xml content below:

package require tdom
set xml \
{<?xml version="1.0"?>
<CBI:PacketDataSummaryReport
xmlns:CBI="http://www.cablelabs.com/namespaces/CBI/2.0/xsd/CBI";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.cablelabs.com/namespaces/CBI/2.0/xsd/
CBI
http://www.cablelabs.com/namespaces/CBI/2.0/xsd/CBI-1.0.xsd";>
<CBI:CaseIdentity>Bill-Kostka</CBI:CaseIdentity>
<CBI:IAPSystemIdentity>cmts-col1.mso.com</CBI:IAPSystemIdentity>
<CBI:TimeStamp>2007-04-06T17:16:34.000000Z</CBI:TimeStamp>
<CBI:AccessSessionId>5671986</CBI:AccessSessionId>
<CBI:PacketSignature>
<CBI:sourceAddress>23.45.32.12</CBI:sourceAddress>
<CBI:destAddress>197.200.1.45</CBI:destAddress>
<CBI:sourcePort>32456</CBI:sourcePort>
<CBI:destPort>80</CBI:destPort>
<CBI:protocol>6</CBI:protocol>
<CBI:NumPktsSinceLastReport>4564</CBI:NumPktsSinceLastReport>
</CBI:PacketSignature>
<CBI:PacketSignature>
<CBI:sourceAddress>197.200.1.45</CBI:sourceAddress>
<CBI:destAddress>23.45.32.12</CBI:destAddress>
<CBI:sourcePort>80</CBI:sourcePort>
<CBI:destPort>32456</CBI:destPort>
<CBI:protocol>6</CBI:protocol>
<CBI:NumPktsSinceLastReport>2855612</CBI:NumPktsSinceLastReport>
</CBI:PacketSignature>
</CBI:PacketDataSummaryReport>}
set doc [dom parse $xml]
set root [$doc documentElement]

After this if i want to select nodes how can i give path for getting
CBI:sourceAddress?
Can someone plz help me on this?
Also to some useful tutorials on tdom package.

See:
http://wiki.tcl.tk/1948

especially the example on that page "XPath Query with namespaces".

Michael
.



Relevant Pages

  • mixing xml, dom and tdom
    ... some code which relies on tDOM but wish - no pun intended - to use SOAP ... Require: xml ... determines whether a segfault occurs or not (the XML package is not ...
    (comp.lang.tcl)
  • Re: TclDOM, tDOM, parsing, Attribute name case sensitivity
    ... In a private email Marian sent me an example script that attempted to ... use tDOM to parse the XML and extract the attribute names. ... did not verify the result for tDOM since I do not use that package). ... I have to say that I'm currently entangled into XML, ...
    (comp.lang.tcl)
  • parsing xml file contents
    ... I am trying to write a script for parsing the xml content below: ... set doc ... Also to some useful tutorials on tdom package. ...
    (comp.lang.tcl)
  • Re: TclXSLT question: best approach?
    ... Tcl script using XSLT and then eval'ing it is something I've been doing ... dom::serialize command because the dom package is separate to the xslt ... know that its intended serialisation is as text rather than as XML. ...
    (comp.lang.tcl)
  • Confusion over directory search order for "use"
    ... I'm going to use a package for this and I've chosen to code the ... config in XML and use XML::Simple to read it in. ... directory in which Global.pm and "tryit" live. ... [henry@neptune henry]$ grep NFB tryit ...
    (comp.lang.perl.misc)