Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading/Modifying data block based on one parameter 1

Status
Not open for further replies.

dmazzini

Programmer
Jan 20, 2004
480
US
Hi

Any ideas....

I am reading a file where I have to extract some information and modify some parameters
based on one value that its not present at the begining of the data "AAL2UPVCI", but its part of a node.
e.g I have to modify parameter4 and parameter5, but if the block contains
<p name="AAL2UPVCI">41</p> I have to put the value for parameter4 and parameter5 corresponding to VCI 41.
Problem is that parameterx have same name in different blocks.


Code:
$PARAMETERS{parameter1}{VCI41}=1000;
$PARAMETERS{parameter1}{VCI47}=500;

Code:
<item>
parameter1
parameter2
parameter3
parameter4  <value to modify based on VCI value>
parameter5
parameter6
parameter7
<p name="AAL2UPVCI">47</p>
parameter2
parameter2
parameter2
<item/>

<item>
parameter1
parameter2
parameter3
parameter4
parameter5
parameter6
parameter7
<p name="AAL2UPVCI">45</p>
parameter2
parameter2
parameter2
<item>

<item>
parameter1
parameter2
parameter3
parameter4
parameter5
parameter6
parameter7
<p name="AAL2UPVCI">49</p>
parameter2
parameter2
parameter2
<item>


Real data looks like this, I wont use XML parser since I just want to read the file and overwrite soem specific values. I will use regex
just not clear for me the logic to use.

Code:
<managedObject class="COCO" version="RN5.0" distName="PLMN-PLMN/RNC-424/COCO-1002" id="192750000001528078">
      <p name="AAL2LossRatio">-3</p>
      <p name="AAL2Multiplexing">Multiplexing disabled</p>
      <p name="AAL2MuxDelay">100</p>
      <p name="AAL2QueueHSDPAWithFC">7000</p>
      <p name="AAL2QueueHSDPAWithoutFC">2048</p>
      <p name="AAL2QueueHSUPA">512</p>
      <p name="AAL2QueueNRTDCHWithFC">7000</p>
      <p name="AAL2QueueNRTDCHWithoutFC">2048</p>
      <p name="AAL2QueueRTDCH">512</p>
      <list name="AAL2SignLinkTP">
        <item>
          <p name="AAL2SigCDVT01Egr">20000</p>
          <p name="AAL2SigCDVT01Ing">20000</p>
          <p name="AAL2SigEarlyPacketDiscard">disabled</p>
          <p name="AAL2SigEgressMDCR">4294967295</p>
          <p name="AAL2SigEgressUBRShare">0</p>
          <p name="AAL2SigIngressMDCR">4294967295</p>
          <p name="AAL2SigIngressUBRShare">0</p>
          <p name="AAL2SigPCR01Egr">50</p>
          <p name="AAL2SigPCR01Ing">50</p>
          <p name="AAL2SigPartialPacketDiscard">disabled</p>
          <p name="AAL2SigServiceCategory">CBR</p>
          <p name="AAL2SignLinkATMIfId">5</p>
          <p name="AAL2SignLinkTPId">1</p>
          <p name="AAL2SignLinkVCI">38</p>
          <p name="AAL2SignLinkVPI">21</p>
        </item>
      </list>
      <list name="AAL2TP">
        <item>
          <p name="AAL2FallbAttribute">Disabled</p>
          <p name="AAL2PathId">1002001</p>
          <p name="AAL2PathType">Stringent</p>
          <p name="AAL2SignLinkATMIfId">5</p>
          <p name="AAL2SignLinkVCI">38</p>
          <p name="AAL2SignLinkVPI">21</p>
          <p name="AAL2UPATMIfId">5</p>
          <p name="AAL2UPCDVT01Egr">334</p>
          <p name="AAL2UPCDVT01Ing">334</p>
          <p name="AAL2UPEgressMDCR">4294967295</p>
          <p name="AAL2UPEgressUBRShare">0</p>
          <p name="AAL2UPIngressMDCR">4294967295</p>
          <p name="AAL2UPIngressUBRShare">0</p>
          <p name="AAL2UPPCR01Egr">3000</p>
          <p name="AAL2UPPCR01Ing">3000</p>
          <p name="AAL2UPServiceCategory">CBR</p>
          <p name="AAL2UPUsage">DCH &amp; HSPA</p>
          <p name="AAL2UPVCI">40</p>
          <p name="AAL2UPVPI">21</p>
          <p name="COCOA2EA">4901002000</p>
          <p name="VCCInBundle">VCC is in first Bundle</p>
          <p name="WAMId">1</p>
        </item>
        <item>
          <p name="AAL2FallbAttribute">Disabled</p>
          <p name="AAL2PathId">1002002</p>
          <p name="AAL2PathType">Tolerant</p>
          <p name="AAL2SignLinkATMIfId">5</p>
          <p name="AAL2SignLinkVCI">38</p>
          <p name="AAL2SignLinkVPI">21</p>
          <p name="AAL2UPATMIfId">5</p>
          <p name="AAL2UPCDVT01Egr">309</p>
          <p name="AAL2UPCDVT01Ing">309</p>
          <p name="AAL2UPEgressMDCR">100</p>
          <p name="AAL2UPEgressUBRShare">50</p>
          <p name="AAL2UPIngressMDCR">100</p>
          <p name="AAL2UPIngressUBRShare">50</p>
          <p name="AAL2UPPCR01Egr">3240</p>
          <p name="AAL2UPPCR01Ing">3240</p>
          <p name="AAL2UPServiceCategory">UBR+</p>
          <p name="AAL2UPUsage">HSPA</p>
          <p name="AAL2UPVCI">46</p>
          <p name="AAL2UPVPI">21</p>
          <p name="COCOA2EA">4901002000</p>
          <p name="VCCInBundle">VCC is in first Bundle</p>
          <p name="WAMId">1</p>
        </item>
        <item>
          <p name="AAL2FallbAttribute">Disabled</p>
          <p name="AAL2PathId">1002003</p>
          <p name="AAL2PathType">Stringent bi-level</p>
          <p name="AAL2SignLinkATMIfId">5</p>
          <p name="AAL2SignLinkVCI">38</p>
          <p name="AAL2SignLinkVPI">21</p>
          <p name="AAL2UPATMIfId">5</p>
          <p name="AAL2UPCDVT01Egr">309</p>
          <p name="AAL2UPCDVT01Ing">309</p>
          <p name="AAL2UPEgressMDCR">20</p>
          <p name="AAL2UPEgressUBRShare">1000</p>
          <p name="AAL2UPIngressMDCR">20</p>
          <p name="AAL2UPIngressUBRShare">1000</p>
          <p name="AAL2UPPCR01Egr">3240</p>
          <p name="AAL2UPPCR01Ing">3240</p>
          <p name="AAL2UPServiceCategory">UBR+</p>
          <p name="AAL2UPUsage">DCH &amp; HSPA</p>
          <p name="AAL2UPVCI">47</p>
          <p name="AAL2UPVPI">21</p>
          <p name="COCOA2EA">4901002000</p>
          <p name="VCCInBundle">VCC is in first Bundle</p>
          <p name="WAMId">1</p>
        </item>
      </list>
      <p name="ATMEPProfileId">0</p>
      <p name="CNBAPCDVT01Egr">20000</p>
      <p name="CNBAPCDVT01Ing">20000</p>
      <p name="CNBAPEarlyPacketDiscard">disabled</p>
      <p name="CNBAPEgressMDCR">4294967295</p>
      <p name="CNBAPEgressUBRShare">0</p>
      <p name="CNBAPIngressMDCR">4294967295</p>
      <p name="CNBAPIngressUBRShare">0</p>
      <p name="CNBAPPCR01Egr">50</p>
      <p name="CNBAPPCR01Ing">50</p>
      <p name="CNBAPPartialPacketDiscard">disabled</p>
      <p name="CNBAPServiceCategory">CBR</p>
      <p name="CNBAPTPATMIfId">5</p>
      <p name="CNBAPVCI">36</p>
      <p name="CNBAPVPI">21</p>
      <p name="COCOChangeOrigin">NetAct RNW plan originated configuration action</p>
      <p name="CalculateCDVT">Calculated</p>
      <p name="CreateATMTP">Created</p>
      <list name="DNBAPTP">
        <item>
          <p name="CControlPortID">1</p>
          <p name="DNBAPATMIfId">5</p>
          <p name="DNBAPCDVT01Egr">10000</p>
          <p name="DNBAPCDVT01Ing">10000</p>
          <p name="DNBAPEarlyPacketDiscard">disabled</p>
          <p name="DNBAPEgressMDCR">4294967295</p>
          <p name="DNBAPEgressUBRShare">0</p>
          <p name="DNBAPIngressMDCR">4294967295</p>
          <p name="DNBAPIngressUBRShare">0</p>
          <p name="DNBAPPCR01Egr">100</p>
          <p name="DNBAPPCR01Ing">100</p>
          <p name="DNBAPPartialPacketDiscard">disabled</p>
          <p name="DNBAPServiceCategory">CBR</p>
          <p name="DNBAPVCI">37</p>
          <p name="DNBAPVPI">21</p>
        </item>
      </list>
      <p name="DynNRTDCHSchedPathSwitch">On</p>
      <p name="GenerateAAL2Num">One A2EA for BTS</p>
      <p name="InternalHSDPAFCMethodBTS">Dynamic</p>
      <list name="VCCBundleParams">
        <item>
          <p name="VCCBundleEBS">95</p>
          <p name="VCCBundleId">78</p>
          <p name="VCCBundlePCR">3240</p>
        </item>
        <item>
          <p name="VCCBundleEBS">95</p>
          <p name="VCCBundleId">65535</p>
          <p name="VCCBundlePCR">4800</p>
        </item>
      </list>
      <list name="VPLTP">
        <item>
          <p name="COCOVPI">21</p>
          <p name="VPLTPATMIfId">5</p>
          <p name="VPLTPCDVT01Egr">279</p>
          <p name="VPLTPEgressMDCR">4294967295</p>
          <p name="VPLTPPCR01Egr">3591</p>
          <p name="VPLTPServiceCategory">CBR</p>
          <p name="VPLTPTrafficShaping">none</p>
        </item>
      </list>
    </managedObject>



dmazzini
GSM/UMTS System and Telecomm Consultant

 
Use an XML Parser. You've not listed a good reason not to, and it will make your job much easier.

XML::Twig is probably what you're after:

Code:
use XML::Twig;

use strict;
use warnings;

my $xml = do {local $/; <DATA>};

my $twig = XML::Twig->new(twig_handlers => {
	'/XML/TestElement' => sub { $_->set_text('Bye') },
});
$twig->parse($xml);
$twig->print();

__DATA__
<XML> <TestElement>Hello</TestElement> </XML>

If you told us the real values you were trying to change and under what conditions, someone could probably write the XML::Twig for you very easily. But this is the tool that you need to use

- Miller
 
Hi Miller, thanks for your prompt answer..

i have already worked with xml::twig in the past. but since i just want to modify few parameters in the xml file based on one specific parameter 'AAL2UPVCI' value. I though that I don't need to use any xml parser since more 'programming is involved'. If you have a look at the xml structure you will see that i will have to work with different subroutines:

1. Getting attributes for 'managedObject'.
2. Getting General Parameters 'managedObject/p'
3. Getting parameters for 'managedObject/list'
4. Getting parameters for 'managedObject/list/item/p'

and then modify with the new values and re-write the file.

Are these good reasons?

i am giving you an example of the parameters to update.

<p name="AAL2UPPCR01Egr">3240</p>
<p name="AAL2UPPCR01Ing">3240</p>

as you can see they are under different nodes but based on AAL2UPVCI value will use different values.









dmazzini
GSM/UMTS System and Telecomm Consultant

 
It took me a while to figure it out as I don't process many XML files nor therefore use any parser typically. But here is a working example of the parsing you want using XML::Twig:

I still don't know exactly how you want to change the values, but as you can see I access each of the nodes that you want to change and get the sibling VCI value that you were wanting it to be dependent on. You can finish the code from there.

Code:
use XML::Twig;

use strict;

my $xml = do {local $/; <DATA>};

my $twig = XML::Twig->new(
	keep_spaces => 1,
);
$twig->parse($xml);

foreach my $node ($twig->findnodes(q{//p[@name='AAL2UPPCR01Egr']})) {
	my $parent = $node->parent();
	my @nodes = $parent->findnodes(q{p[@name='AAL2UPVCI']});
	if (@nodes == 1) {
		my $vci = $nodes[0]->text();
		$node->set_text($vci . ' - ' . $node->text());
	} else {
		warn "Invalid number of VCI nodes";
		$parent->print();
	}
}

foreach my $node ($twig->findnodes(q{//p[@name='AAL2UPPCR01Ing']})) {
	my $parent = $node->parent();
	my @nodes = $parent->findnodes(q{p[@name='AAL2UPVCI']});
	if (@nodes == 1) {
		my $vci = $nodes[0]->text();
		$node->set_text($vci . ' - ' . $node->text());
	} else {
		warn "Invalid number of VCI nodes";
		$parent->print();
	}
}

$twig->print();

__DATA__
<managedObject class="COCO" version="RN5.0" distName="PLMN-PLMN/RNC-424/COCO-1002" id="192750000001528078">
      <p name="AAL2LossRatio">-3</p>
      <p name="AAL2Multiplexing">Multiplexing disabled</p>
      <p name="AAL2MuxDelay">100</p>
      <p name="AAL2QueueHSDPAWithFC">7000</p>
      <p name="AAL2QueueHSDPAWithoutFC">2048</p>
      <p name="AAL2QueueHSUPA">512</p>
      <p name="AAL2QueueNRTDCHWithFC">7000</p>
      <p name="AAL2QueueNRTDCHWithoutFC">2048</p>
      <p name="AAL2QueueRTDCH">512</p>
      <list name="AAL2SignLinkTP">
        <item>
          <p name="AAL2SigCDVT01Egr">20000</p>
          <p name="AAL2SigCDVT01Ing">20000</p>
          <p name="AAL2SigEarlyPacketDiscard">disabled</p>
          <p name="AAL2SigEgressMDCR">4294967295</p>
          <p name="AAL2SigEgressUBRShare">0</p>
          <p name="AAL2SigIngressMDCR">4294967295</p>
          <p name="AAL2SigIngressUBRShare">0</p>
          <p name="AAL2SigPCR01Egr">50</p>
          <p name="AAL2SigPCR01Ing">50</p>
          <p name="AAL2SigPartialPacketDiscard">disabled</p>
          <p name="AAL2SigServiceCategory">CBR</p>
          <p name="AAL2SignLinkATMIfId">5</p>
          <p name="AAL2SignLinkTPId">1</p>
          <p name="AAL2SignLinkVCI">38</p>
          <p name="AAL2SignLinkVPI">21</p>
        </item>
      </list>
      <list name="AAL2TP">
        <item>
          <p name="AAL2FallbAttribute">Disabled</p>
          <p name="AAL2PathId">1002001</p>
          <p name="AAL2PathType">Stringent</p>
          <p name="AAL2SignLinkATMIfId">5</p>
          <p name="AAL2SignLinkVCI">38</p>
          <p name="AAL2SignLinkVPI">21</p>
          <p name="AAL2UPATMIfId">5</p>
          <p name="AAL2UPCDVT01Egr">334</p>
          <p name="AAL2UPCDVT01Ing">334</p>
          <p name="AAL2UPEgressMDCR">4294967295</p>
          <p name="AAL2UPEgressUBRShare">0</p>
          <p name="AAL2UPIngressMDCR">4294967295</p>
          <p name="AAL2UPIngressUBRShare">0</p>
          <p name="AAL2UPPCR01Egr">3000</p>
          <p name="AAL2UPPCR01Ing">3000</p>
          <p name="AAL2UPServiceCategory">CBR</p>
          <p name="AAL2UPUsage">DCH &amp; HSPA</p>
          <p name="AAL2UPVCI">40</p>
          <p name="AAL2UPVPI">21</p>
          <p name="COCOA2EA">4901002000</p>
          <p name="VCCInBundle">VCC is in first Bundle</p>
          <p name="WAMId">1</p>
        </item>
        <item>
          <p name="AAL2FallbAttribute">Disabled</p>
          <p name="AAL2PathId">1002002</p>
          <p name="AAL2PathType">Tolerant</p>
          <p name="AAL2SignLinkATMIfId">5</p>
          <p name="AAL2SignLinkVCI">38</p>
          <p name="AAL2SignLinkVPI">21</p>
          <p name="AAL2UPATMIfId">5</p>
          <p name="AAL2UPCDVT01Egr">309</p>
          <p name="AAL2UPCDVT01Ing">309</p>
          <p name="AAL2UPEgressMDCR">100</p>
          <p name="AAL2UPEgressUBRShare">50</p>
          <p name="AAL2UPIngressMDCR">100</p>
          <p name="AAL2UPIngressUBRShare">50</p>
          <p name="AAL2UPPCR01Egr">3240</p>
          <p name="AAL2UPPCR01Ing">3240</p>
          <p name="AAL2UPServiceCategory">UBR+</p>
          <p name="AAL2UPUsage">HSPA</p>
          <p name="AAL2UPVCI">46</p>
          <p name="AAL2UPVPI">21</p>
          <p name="COCOA2EA">4901002000</p>
          <p name="VCCInBundle">VCC is in first Bundle</p>
          <p name="WAMId">1</p>
        </item>
        <item>
          <p name="AAL2FallbAttribute">Disabled</p>
          <p name="AAL2PathId">1002003</p>
          <p name="AAL2PathType">Stringent bi-level</p>
          <p name="AAL2SignLinkATMIfId">5</p>
          <p name="AAL2SignLinkVCI">38</p>
          <p name="AAL2SignLinkVPI">21</p>
          <p name="AAL2UPATMIfId">5</p>
          <p name="AAL2UPCDVT01Egr">309</p>
          <p name="AAL2UPCDVT01Ing">309</p>
          <p name="AAL2UPEgressMDCR">20</p>
          <p name="AAL2UPEgressUBRShare">1000</p>
          <p name="AAL2UPIngressMDCR">20</p>
          <p name="AAL2UPIngressUBRShare">1000</p>
          <p name="AAL2UPPCR01Egr">3240</p>
          <p name="AAL2UPPCR01Ing">3240</p>
          <p name="AAL2UPServiceCategory">UBR+</p>
          <p name="AAL2UPUsage">DCH &amp; HSPA</p>
          <p name="AAL2UPVCI">47</p>
          <p name="AAL2UPVPI">21</p>
          <p name="COCOA2EA">4901002000</p>
          <p name="VCCInBundle">VCC is in first Bundle</p>
          <p name="WAMId">1</p>
        </item>
      </list>
      <p name="ATMEPProfileId">0</p>
      <p name="CNBAPCDVT01Egr">20000</p>
      <p name="CNBAPCDVT01Ing">20000</p>
      <p name="CNBAPEarlyPacketDiscard">disabled</p>
      <p name="CNBAPEgressMDCR">4294967295</p>
      <p name="CNBAPEgressUBRShare">0</p>
      <p name="CNBAPIngressMDCR">4294967295</p>
      <p name="CNBAPIngressUBRShare">0</p>
      <p name="CNBAPPCR01Egr">50</p>
      <p name="CNBAPPCR01Ing">50</p>
      <p name="CNBAPPartialPacketDiscard">disabled</p>
      <p name="CNBAPServiceCategory">CBR</p>
      <p name="CNBAPTPATMIfId">5</p>
      <p name="CNBAPVCI">36</p>
      <p name="CNBAPVPI">21</p>
      <p name="COCOChangeOrigin">NetAct RNW plan originated configuration action</p>
      <p name="CalculateCDVT">Calculated</p>
      <p name="CreateATMTP">Created</p>
      <list name="DNBAPTP">
        <item>
          <p name="CControlPortID">1</p>
          <p name="DNBAPATMIfId">5</p>
          <p name="DNBAPCDVT01Egr">10000</p>
          <p name="DNBAPCDVT01Ing">10000</p>
          <p name="DNBAPEarlyPacketDiscard">disabled</p>
          <p name="DNBAPEgressMDCR">4294967295</p>
          <p name="DNBAPEgressUBRShare">0</p>
          <p name="DNBAPIngressMDCR">4294967295</p>
          <p name="DNBAPIngressUBRShare">0</p>
          <p name="DNBAPPCR01Egr">100</p>
          <p name="DNBAPPCR01Ing">100</p>
          <p name="DNBAPPartialPacketDiscard">disabled</p>
          <p name="DNBAPServiceCategory">CBR</p>
          <p name="DNBAPVCI">37</p>
          <p name="DNBAPVPI">21</p>
        </item>
      </list>
      <p name="DynNRTDCHSchedPathSwitch">On</p>
      <p name="GenerateAAL2Num">One A2EA for BTS</p>
      <p name="InternalHSDPAFCMethodBTS">Dynamic</p>
      <list name="VCCBundleParams">
        <item>
          <p name="VCCBundleEBS">95</p>
          <p name="VCCBundleId">78</p>
          <p name="VCCBundlePCR">3240</p>
        </item>
        <item>
          <p name="VCCBundleEBS">95</p>
          <p name="VCCBundleId">65535</p>
          <p name="VCCBundlePCR">4800</p>
        </item>
      </list>
      <list name="VPLTP">
        <item>
          <p name="COCOVPI">21</p>
          <p name="VPLTPATMIfId">5</p>
          <p name="VPLTPCDVT01Egr">279</p>
          <p name="VPLTPEgressMDCR">4294967295</p>
          <p name="VPLTPPCR01Egr">3591</p>
          <p name="VPLTPServiceCategory">CBR</p>
          <p name="VPLTPTrafficShaping">none</p>
        </item>
      </list>
    </managedObject>

 
Amazing job Miller, nice, clean and brilliant!

I have thousands COCOs in the XML file, so first of all I am extracting COCO to process from the big file using the distName="PLMN-PLMN/RNC-$rncid/COCO-$coco_id".(This part I just did, however I might start playing with your XML::Twig to do it more elegant)

Then, I will update the parameters based on some other values coming from one excel file. I built a structure from the xls file.


Code:
$COCOPAR{COCO TYPE}{VCI}{PARAMETERNAME}=VALUE;
e.g
$COCOPAR{"8T1_DUAL_IUB"}{40}{CNBAPPCR01Egr}=407;

Something like this will work

Many thanks

Code:
use XML::Twig;

use strict;

my %COCOPAR;

my $xml = do {local $/; <DATA>};

my $twig = XML::Twig->new(
    keep_spaces => 1,
);
$twig->parse($xml);

$COCOPAR{"8T1_DUAL_IUB"}{40}{AAL2UPPCR01Egr}=99999;

foreach my $node ($twig->findnodes(q{//p[@name='AAL2UPPCR01Egr']})) {
    my $parent = $node->parent();
    
    my @nodes = $parent->findnodes(q{p[@name='AAL2UPVCI']});
    if (@nodes == 1) {
        my $vci = $nodes[0]->text();
        print "VCI:$vci\n";  
        if ($vci==40) {           
            #$node->set_text($vci . ' - ' . $node->text());
            $node->set_text($COCOPAR{"8T1_DUAL_IUB"}{$vci}{AAL2UPPCR01Egr});
        }
        if ($vci==46) {           
            #$node->set_text($vci . ' - ' . $node->text());
            $node->set_text("Value for PCR for VCI46");
        }
        if ($vci==47) {           
            #$node->set_text($vci . ' - ' . $node->text());
            $node->set_text("Value for PCR for VCI47");
        }
    } else {
        warn "Invalid number of VCI nodes";
        $parent->print();
    }
}

foreach my $node ($twig->findnodes(q{//p[@name='AAL2UPPCR01Ing']})) {
    my $parent = $node->parent();
    my @nodes = $parent->findnodes(q{p[@name='AAL2UPVCI']});
    if (@nodes == 1) {
        my $vci = $nodes[0]->text();
        $node->set_text($vci . ' - ' . $node->text());
    } else {
        warn "Invalid number of VCI nodes";
        $parent->print();
    }
}

$twig->print();



dmazzini
GSM/UMTS System and Telecomm Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top