List Info

Thread: Regarding XML::LibXML::Element




Regarding XML::LibXML::Element
user name
2007-08-24 10:28:20
Hi there,

I'm creating and modifying XML file using perl module XML::LibXML::Element.

But I'm getting Error when I'm using "appendChild" method. Atlast I found that there is no Element.pm in XML::LibXML distribution.

Any pointers in this. How can I modify XML file using XML::LibXML.

Answers appreciated

Thanks,
Karthick
Re: Regarding XML::LibXML::Element
country flaguser name
Germany
2007-08-24 10:35:56
* Karthick Radhakrishnan wrote:
>I'm creating and modifying XML file using perl module
XML::LibXML::Element.
>
>But I'm getting Error when I'm using
"appendChild" method. Atlast I found
>that there is no Element.pm in XML::LibXML
distribution.

There is no module XML::LibXML::Element, there is only a
package with
that name in the XML::LibXML module. Presumably you tried to
`use XML::
LibXML::Element;` which will fail. You have to `use
XML::LibXML;` and
the package will become available.
-- 
Björn Höhrmann · mailto:bjoernhoehrmann.de · http://bjoern.hoehrmann.de

Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de

68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 
_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

Re: Regarding XML::LibXML::Element
user name
2007-08-24 11:44:26
On Fri, 2007-08-24 at 20:58 +0530, Karthick Radhakrishnan
wrote:
> Hi there,
> 
> I'm creating and modifying XML file using perl module
> XML::LibXML::Element.
> 
> But I'm getting Error when I'm using
"appendChild" method. Atlast I
> found that there is no Element.pm in XML::LibXML
distribution.
> 

What error are you getting?

As Björn pointed out there is no separate
XML::LibXML::Element module.

/J
-- 
This signature kills bloggers
_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
Re: Regarding XML::LibXML::Element
user name
2007-08-26 23:58:50
Bjoern & Jonathan,
Thanks for your reply. Here is the detailed one.
There is no module XML::LibXML::Element. Instead of package I said module. sorry for that.

I'm trying to insert a new tag. See below xml

The Error I got is
";
Can';t locate object method "appendChild" via package "XML::LibXML::NodeList"; at xmlCreate.pl line 34.
"

Code
use strict;
use warnings;
use XML::LibXML;

my $xmlFile = "library.xml";
my $isbn = "076455106X";;

my $xmlObj = XML::LibXML->new();
my $doc = $xmlObj->parse_file($xmlFile);
my $book ; = $doc->findnodes("//book[isbn = '$isbn']";);

my ($rating) = $doc->createElement('rating');
$rating->appendTextNode('5');
$book->appendChild($rating);
#$book->;appendTextChild('rating', '5';);

xml file
<;?xml version=&quot;1.0&quot;?>
&nbsp; <library>
&nbsp; &nbsp; <book&gt;
   ; &nbsp; <title&gt;Perl Best Practices&lt;/title&gt;
   ; &nbsp; <author>Damian Conway</author>
 &nbsp; &nbsp;  <isbn&gt;0596001738</isbn&gt;
 ; &nbsp; &nbsp; <pages&gt;542</pages>
 &nbsp; &nbsp;  <image src="http://www.oreilly.com/catalog/covers/perlbp.s.gif&quot;
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; width=&quot;145" height=&quot;190"; />
&nbsp; &nbsp; </book&gt;
 ; &nbsp; <book&gt;
   ; &nbsp; <title&gt;Perl Cookbook, Second Edition<;/title>
 &nbsp; &nbsp;  <author>Tom Christiansen</author>
&nbsp; &nbsp;   <author>Nathan Torkington</author>
&nbsp; &nbsp; &nbsp; <isbn&gt;0596003137</isbn&gt;
 ; &nbsp; &nbsp; <pages&gt;964</pages>
 &nbsp; &nbsp;  <image src="http://www.oreilly.com/catalog/covers/perlckbk2.s.gi
+f"
 &nbsp; &nbsp; &nbsp;   ; &nbsp;  width=&quot;145" height=&quot;190"; />
&nbsp; &nbsp; </book&gt;
 ; &nbsp; <book&gt;
   ; &nbsp; <title&gt;Guitar for Dummies<;/title>
 &nbsp; &nbsp;  <author>Mark Phillips&lt;/author&gt;
   ; &nbsp; <author>John Chappell&lt;/author&gt;
   ; &nbsp; <isbn&gt;076455106X</isbn&gt;
 ; &nbsp; &nbsp; <pages&gt;392</pages>
 &nbsp; &nbsp;  <image src="http://media.wiley.com/product_data/coverImage/6X/07
+645510/076455106X.jpg"
  ; &nbsp; &nbsp; &nbsp; &nbsp;   width=&quot;100" height=&quot;125"; />
&nbsp; &nbsp; </book&gt;
 ; </library>

Thanks,
Karthick

On 8/24/07, Jonathan Stowe < jnsgellyfish.com">jnsgellyfish.com> wrote:
On Fri, 2007-08-24 at 20:58 +0530, Karthick Radhakrishnan wrote:
>; Hi there,
>;
> I'm creating and modifying XML file using perl module
>; XML::LibXML::Element.
>
> But I'm getting Error when I'm using "appendChild&quot; method. Atlast I
> found that there is no Element.pm in XML::LibXML distribution.
>

What error are you getting?

As Björn pointed out there is no separate XML::LibXML::Element module.

/J
--
This signature kills bloggers
_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com">Perl-XMLlistserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Regarding XML::LibXML::Element
user name
2007-08-27 01:39:44
On Mon, 2007-08-27 at 10:28 +0530, Karthick Radhakrishnan
wrote:
> Bjoern & Jonathan,
> Thanks for your reply. Here is the detailed one.
> There is no module XML::LibXML::Element. Instead of
package I said
> module. sorry for that.
> 
> I'm trying to insert a new tag. See below xml
> 
> The Error I got is
> "
> Can't locate object method "appendChild" via
package
> "XML::LibXML::NodeList" at xmlCreate.pl line
34.
> "
> 
> Code
> use strict;
> use warnings;
> use XML::LibXML;
> 
> my $xmlFile = "library.xml";
> my $isbn = "076455106X";
> 
> my $xmlObj = XML::LibXML->new();
> my $doc = $xmlObj->parse_file($xmlFile);
> my $book  = $doc->findnodes("//book[isbn =
'$isbn']");
> 


In a scalar context (such as you have above) findnodes()
returns an
XML::LibXML::NodeList object - irrespective  of the number
of nodes
found.  If you are absolutely sure that you will only find
one node with
your expression then you can do:

   my $book  = ($doc->findnodes("//book[isbn =
'$isbn']"))[0];

(i.e putting the RHS in a list context and taking the first
element of
the list or:

  my $book  = $doc->findnodes("//book[isbn =
'$isbn']")->shift();

(i.e. shift() the first element off the
XML::LibXML::NodeList )

/J

-- 
Winners don't do de-tox
_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )