Re: libxml2 application data

"Tod Harter" <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
Uh, isn't that the purpose of the 'id' attribute of an element? Granted,
such an attribute may not exist in documents which come from external
sources, but it may be fairly straightforward to just go ahead and add one.
I can think of a number of possible ways to do that which may be fairly
painless.

1) Once you parse your XML into a DOM tree run a small XSLT transform on it
to add id attributes where desired. The required XSLT should be fairly
trivial and could be supplied by a 'here document' etc. Probably requires
maybe 10-15 lines of XSLT total and 5-6 lines of perl.

2) If you don't want to use XSLT for that, it can probably be accomplished
with maybe 20 lines of perl DOM/XPath code. Might be a bit more depending on
the complexity of what you need to do, but it shouldn't be too tough.

3) Should also be possible to preprocess the incoming XML. That could be
accomplished either via using the push parser (IE read the incoming document
in perl, make some changes via regex etc and then feed it to push parser),
or it could be done using XML::LibXML callbacks, which also let you handle
I/O and basically the same sort of logic would apply. This method may be
'brittle' in the sense that it is possible some syntactically correct XML
might get past your regex, but should work pretty well in reality.

On Mon, Dec 22, 2008 at 8:48 AM, philippe marguinaud <
[email protected]> wrote:

>  Hi Petr,
>
> I have thought about using the $$node trick, but when the XML tree is
> modified ( for instance when a node is deleted ), then some of the nodes are
> re-numbered. I can provide a demo script to illustrate this if you want.
> So I am stuck with XML::LibXML, I will have to find another module...
>
> Regards,
>
> Philippe
>
> > From: [email protected]
> > To: [email protected]
> > Subject: Re: libxml2 application data
> > Date: Mon, 22 Dec 2008 12:14:20 +0100
> > CC: [email protected]
> >
> > No, XML::LibXML uses the _private slot for its own purposes. I'd
> > suggest using a Perl hash and $$node as key ($$node is an integer
> > that uniquely identifies a libxml2's node).
> >
> > -- Petr
> >
> > On ne 21. prosince 2008, philippe marguinaud wrote:
> > > Hi all,
> > >
> > > I have written C programs using libxml2 and used to attach
> > > application data to xml nodes using the _private field of node
> > > structs. I would like to know whether it is possible to do that
> > > using the Perl bindings; I have not seen anything like that in
> > > the pod documentation.
> > >
> > > Regards,
> > >
> > > Philippe
> > >
> > > _________________________________________________________________
> > > Invite your mail contacts to join your friends list with Windows
> > > Live Spaces. It's easy!
> > > http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/fr
> > >iends.aspx&mkt=en-us
> >
> >
>
> ------------------------------
> Get easy photo sharing with Windows Live™ Photos. Drag n' drop<http://www.microsoft.com/windows/windowslive/photos.aspx>
>
> _______________________________________________
> Perl-XML mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
>


-- 
The Wise adapts himself to the world. The Fool adapts the world to himself.
Therefore, all progress depends on the Fool.

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.