School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,220 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,680 people online right now. Registration is fast and FREE... Join Now!




Adding attribute to XML using perl (XPath)

 

Adding attribute to XML using perl (XPath)

Sun751

21 Jun, 2009 - 10:16 PM
Post #1

D.I.C Head
**

Joined: 11 Dec, 2008
Posts: 57



Thanked: 1 times
My Contributions
Structure of my XML file is like this
CODE

<CONFIGURATION
  <APPLICATION_SERVER>
       <RESOURCE_LIST>
      <PLATFORM_INDEPENDENT>
            <RESOURCE Id="res.wacgen" Source="INTERNAL">$(res.appl)</RESOURCE>
    <RESOURCE Id="res.wacgenlib" Source="INTERNAL">$(res.appl)$(res.slash)all.4gm</RESOURCE>
    <RESOURCE Id="res.waclibext" Source="INTERNAL">4gs</RESOURCE>
    <RESOURCE Id="res.fcode" Source="INTERNAL">rt.2.10.01-1138</RESOURCE>
    <RESOURCE Id="res.frunext" Source="INTERNAL">ifx</RESOURCE>
    <RESOURCE Id="res.db_type" Source="INTERNAL">msv</RESOURCE>

          </PLATFORM_INDEPENDENT>
        </RESOURCE_LIST>
      </APPLICATION_SERVER>
</CONFIGURATION


And i am trying to check each attribute like this,

CODE

my $source = '/sand/devel/sthapa/tmp/as.xcf-dist';
my $Tag_Resource ='/CONFIGURATION/APPLICATION_SERVER/RESOURCE_LIST/';
my $Tag_Resource_PI=$Tag_Resource.'PLATFORM_INDEPENDENT/RESOURCE';
    my $Tag_wnt=$Tag_Resource.'WNT/RESOURCE';
    my $os_res_group;

    my $parser=new XML::XPath->new(filename => $source);
    $parser or die "Unable to parse sourse file: $source\n";

    my $Set_Resource = $parser->find($Tag_Resource_PI);

    foreach my $resource ($Set_Resource->get_nodelist)
    {
        my $attribute=$resource->getAttribute('Id');
        my $child_node = $resource->getChildNodes();
        if (exists $$HRR_resource{$attribute})
        {
        print "Attribute exists: $attribute";
        }
        else
        {
         #Add attribute to XML
        }

So I am trying to add all the attribute whichever does not exists in hash to XML using XML::XPath,

but I am not being able to do that,

any one have any suggestion???


User is offlineProfile CardPM
+Quote Post


Posts in this topic
Sun751   Adding attribute to XML using perl (XPath)   21 Jun, 2009 - 10:16 PM

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 10:28PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month