Apache OpenOffice (AOO) Bugzilla – Issue 118514
Faulty method getElementsByTagName with com.sun.star.xml.dom.XElement resp. XDocument
Last modified: 2013-01-23 01:31:03 UTC
Created attachment 76891 [details] Fancy xml file as test object for the getElementsByTagName bug Importing xml files with DOM. The getElementsByTagName method of the interfaces com.sun.star.xml.dom.XDocument and com.sun.star.xml.dom.XDocument yields faulty results for tag names of length 8 and 16 (no longer names tested). Usually the bug doesn't show with only few elements. You can force the bug to become visible by multiple calls to the test below or by increasing the number of iterations. OOo gets unstable and is apt to crash. I attach a short fancy xml file. You can use this test on the file. Sub Test Dim sURL As String Dim oDocBuilder Dim oDOM Dim i% Dim oElements Dim sTagName As String sTagName = "validTo" 'Length 7: okay -> 10 elements 'sTagName = "document" 'Length 8: faulty -> 10 elements 'sTagName = "slot" 'Length 4: okay -> 13 elements 'sTagName = "customer" 'Length 8: faulty -> 18 elements sURL = "your_path" oDocBuilder = createUnoService("com.sun.star.xml.dom.DocumentBuilder") oDOM = oDocBuilder.parseURI(sUrl) oDOM.normalize() If IsEmpty(oDOM) Then Exit Sub oElements = oDOM.getElementsByTagName(sTagName) ' Print oElements.getLength ' Exit Sub For i = 0 To 10 'With "slot" and "validTo" even 10000 is ok If oElements.getLength <> 10 Then 'Number depends on the tag name (s.a.) Print i, "Error" Exit Sub End If Next Print "Done" End Sub Volker Lenhardt
Sorry, copying the the test code from my module I mixed up important lines. The code has to be changed to become meaningful: Sub Test Dim sURL As String Dim oDocBuilder Dim oDOM Dim i% Dim oElements Dim sTagName As String sTagName = "validTo" 'Length 7: okay -> 10 elements 'sTagName = "document" 'Length 8: faulty -> 10 elements 'sTagName = "slot" 'Length 4: okay -> 13 elements 'sTagName = "customer" 'Length 8: faulty -> 18 elements sURL = "your_path" oDocBuilder = createUnoService("com.sun.star.xml.dom.DocumentBuilder") oDOM = oDocBuilder.parseURI(sUrl) oDOM.normalize() If IsEmpty(oDOM) Then Exit Sub For i = 0 To 10 'With "slot" and "validTo" even 10000 is ok oElements = oDOM.getElementsByTagName(sTagName) If oElements.getLength <> 10 Then 'Number depends on the tag name (s.a.) Print i, "Error" Exit Sub End If Next Print "Done" End Sub