11

How can one open an XML file, for example with LibreOffice? If I try, all I see is the text format of XML, with tags and so on.

PJTraill
  • 107
  • 5
Luigi
  • 492
  • 1
  • 5
  • 9
  • 1
    Hi do you wish to edit the file or just view it? You can use gedit https://help.ubuntu.com/community/gedit ubuntu's build in text editor. – gman Feb 25 '14 at 12:07
  • XML files are text files, so any text editor can open it. But if you want to perform XML validation on it, then you need some XML editor that will also load the XSD file related to the XML and perform the validation (check that you enter the correct tag with the correct value type). – Benoit Mar 14 '14 at 14:42
  • 2
    And what exactly were you expecting? It's an XML file! – terdon Mar 15 '14 at 21:08

6 Answers6

15

If the file is an XML table, you can open it in LibreOffice Calc through the Data > XML Source menu1. Inside it, you just need to open the XML file, point to the table you're importing on the left column and specify a destination in your sheet in the right text field. Example:

enter image description here

This feature is documented in the Help for LibreOffice Calc and at https://wiki.documentfoundation.org/Development/Calc/XMLSource .

1 Since this is an experimental feature (at least in V 6.1.3.2), it may be unreliable and the menu entry will be greyed out unless experimental features are enabled with ToolsOptionsLibreOfficeAdvancedEnable experimental features.

Waldir Leoncio
  • 1,897
  • 4
  • 29
  • 43
  • What is an "xml table"? How do I find out if my file is one or has one? When I open a file like that, I see nothing in the "Map to document" window, though I see " lines in it. It comes from SOE Software's Clarity Election Night Reporting tool, e.g. the detail.xls file zipped inside http://results.enr.clarityelections.com/CO/63746/183083/reports/detailtxt.zip – nealmcb Nov 12 '16 at 15:13
  • Cool, this works in LibreOffice Calc 5.1 with sitemap.xml from a sitemap generator service. I can choose which column to be shown in the sheet. Thanks Waldir. – Ade Malsasa Akbar May 03 '18 at 08:28
  • Quite, what is an XML table? Is it a collection of repeated nodes all of which have the same set of attributes in a two- or three-level structure? Is it converted to a table with each row corresponding to one of the first-level nodes? – PJTraill Mar 30 '19 at 22:05
  • When I try this (in LibreOffice Calc 6.1.3.2 on Open Suse Leap), XML source is greyed out in the Data menu – do I have to do something else first? – PJTraill Mar 30 '19 at 22:07
  • Some documentation at https://wiki.documentfoundation.org/Development/Calc/XMLSource , as referenced in the Help (but it says nothing about ungreying the menu entry). – PJTraill Mar 30 '19 at 22:14
  • Have now found how to enable this experimental feature and added that to the answer, but it is pending peer review; if and when accepted I shall clean up my comments. – PJTraill Mar 30 '19 at 23:11
  • When I try this, the `Mapped cell` remains grey and unwritable for all elements in my tree, with no explanation given (as noted at https://wiki.documentfoundation.org/Development/Calc/XMLSource#Display_explanation_on_non-selectable_element.2Fattribute ). – PJTraill Mar 30 '19 at 23:18
3

You can also use basex from the software center.

sudo apt-get install basex

BaseX is a very fast and light-weight, yet powerful XML database and XPath/XQuery processor, including support for the latest W3C Full Text and Update Recommendations. It supports large XML instances and offers a highly interactive front-end (basexgui).

I don't have it installed but it has really high ratings from the software center.

Parto
  • 15,027
  • 24
  • 86
  • 114
0

You may find XMLStarlet useful, if you are familiar with XPATH concepts (or prepared to learn them).

This is a command-line tool which can select data from an XML file on the basis of the types of elements and the values of their attributes or those of related elements. I am not sure if it is easy to generate a CSV file or other suitable for loading into LibreOffice (if that is your aim), or whether you would need to transform it a little first. (I shall try to remember to update this if I find out more.)

The examples given in the Wikipedia article (link above) show the command as xml (e.g. xml sel for a selection), but in my case (OpenSuse Leap) it is xmlstarlet, which is also the package to install; I do not know what the situation is for Ubuntu.

PJTraill
  • 107
  • 5
0

The default Gedit text editor is capable of opening the file - I also suggest you try Bluefish, which can do XML as well HTML and other languages. It also does auto-completion, and highlighting.

Here are examples of the above editors based on this:

Bluefish screenshot

enter image description here N.B. With Gedit, you have to add some of the above by changing a few settings and activating a few plugins.

Wilf
  • 29,694
  • 16
  • 106
  • 164
0

In case you don't succeed with LibreOffice, try using SoftMaker FreeOffice. This free office suite has much better import and export filters that let you run Microsoft Office formats faithfully. The whole office suite is feature-packed, but needs only 58MB. It's well coded, very fast and reliable. Here's the link where to get it:

www.freeoffice.com

0

XML Copy Editor (xmlcopyeditor) is a fast, free, validating XML editor. It features DTD/XML Schema/RELAX NG validation, XSLT, XPath, pretty-printing, syntax highlighting, folding, tag completion/locking, and a spelling/style check. XML Copy Editor can be installed from the default Ubuntu repositories.

XML Copy Editor debugger (xmlcopyeditor-dbg) is an optional add-on for XML Copy Editor that can also be installed from the default Ubuntu repositories.

enter image description here

karel
  • 110,292
  • 102
  • 269
  • 299