Re: XML::LibXML - Mixing XPath with a document fragment
Manuel Souto Pico <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I have a long XML document in which several branches have repeated
contents, for example
<document>
...
<entry ="10">
<Eng>house</Eng>
<Spa>casa</Spa>
</entry>
<entry ="11">
<Eng>shoe</Eng>
<Spa>zapato</Spa>
</entry>
<entry ="12">
<Eng>house</Eng>
<Spa>casa</Spa>
</entry>
...
</document>
where as you can see, entries 10 and 12 have identical contents.
My question is: Is there any easy way to spot and/or remove repeated
elements? I suppose it could be done with XSL or a perl module for XML...
Any help would be very appreciated.
Manuel Souto Pico
Terminólogo / Responsable de servicio técnico
*STAR Servicios Lingüísticos, SL*
C. Sardenya, 195-197 (baixos)
E-08013 Barcelona
Tel. +34 932 440 881
Fax: +34 932 471 273
[email protected] <mailto:[email protected]>
http://www.star-spain.com
Emmanuel Rodriguez escribió:
> On Thu, Jan 29, 2009 at 11:12 AM, Petr Pajas <[email protected]> wrote:
>
>> On čt 29. ledna 2009, Petr Pajas wrote:
>>
>>> On čt 29. ledna 2009, Emmanuel Rodriguez wrote:
>>>
>>>> Hi,
>>>>
>>>> I have an XML document that was generated with document
>>>> fragments by an external function. This gave me some struggle
>>>> because I was trying to use an XPath expression to access some
>>>> nodes and couldn't reach them. This is due to the fact that
>>>> even though the document fragment seems transparent it's still
>>>> in the document and brakes the parent/child/sibling relation
>>>> ship. This makes it a difficult to use XPath to search for
>>>> nodes.
>>>>
>>>> Is there a way to clean document of all document fragments
>>>> besides $xml =
>>>> XML::LibXML->new()->parse_string($xml->toString()); ? Should
>>>> document fragments be avoided?
>>>>
>>>> For the curious, I have attached a test case that shows the
>>>> problems I had parsing the document.
>>>>
>>> Hallo Emmanuel!
>>>
>>> A fragment node should never have appeared as a child of another
>>> node; that's the bug!
>>>
>> oh, and the bug is documented:-)
>>
>> addChild:
>>
>> As an alternative to appendChild() one can use the addChild()
>> function. This function is a bit faster, because it avoids all DOM
>> conformity checks.
>>
>> Well, in that case I might just add a simple node-type test and
>> croak on fragments (and possibly other invalid node types). That
>> will not cause any significant slow down.
>>
>> One should use appendChild() for correct DOM behavior.
>>
>>
> Thanks Petr.
>
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs