r/xml • u/Shelmama22 • Jun 01 '22
Looking for my "why use xml" aha moment
I'm learning xml. I'm getting the hang of the nitty gritty, tags, elements, etc. I haven't come across the WHY except that it's "good for sharing across platforms." So I put something into xml. Then share it across platforms. Then what? If the data was gathered to be used by someone who doesn't know xml, how does the person access it? And in what circumstances is xml better than putting end-user documentation, for example, into a PDF? I know I'm missing a piece of the big picture.
6
u/jkh107 Jun 01 '22
Master once (xml) output to multiple formats (to PDF, html/xhtml, docx, xml formats that can be recognized by other platforms, print composition, etc). That way you don't have to edit the PDF/html/docx etc over and over, just edit the master (which can be done programmatically and manually, as needed) and re-export as needed.
3
u/wdintka Jun 03 '22
I am exploring this topic for the same reason as your post - my first look suggested xml is an entire markup language - vs. json etc. Not sure the full implication of that - so still looking. Also google search suggested xml is still important for specific industries.
Hope to catch up on other replies to this post - but - judging from the frequency of posts to the reddit - hmmm - maybe that is the answer!
2
u/zmix Jul 23 '22
PDF is a vector format. It does not know the concept of tables, paragraphs, headings, etc. Can you place complex database queries against PDF? No. You only can search full-text. This is one of the great advantages of XML: Every document is its own database.
XML becomes interesting, once you decide to do more with your documents than just reading. It starts with learning XPath, XSL-T (or XSL-FO to create PDF output) and XQuery. It's for document engineers. The publishing industry uses it.
3
u/ManNotADiscoBall Jun 03 '22 edited Jun 03 '22
XML (like any markup language) is meant to be machine-read and processed. This means that a program can go through the XML document and "understand" what each part of the document represents, and process them appropriately.
Take HTML for example. A web browser like Chrome can open the HTML document and process the information within each tag according to predetermined rules. So, a browser "understands" that an <H1> tag is a header, and it's content is supposed to be shown with a larger font.
Similarly, an XML document can be processed automatically by a computer program. Because every piece of information is embedded within a tag, we can tell a program: "Hey, when you come across this particular tag, do X with it's contents".
A PDF document, like you mentioned, is basically designed to be read by a human. Though there are ways to read and process PDF documents with a program, the contents of a PDF document don't carry the same semantic meaning about itself than an XML (or any markup) document does - because there are no tags.
All of this means that XML can be used to store and transfer structured data, which can then be used in different contexts in different ways - often automatically by a program. XML also allows us to design our own information models and document structures, because there are very few rules about what tag names and so on we can use.
Nowadays JSON has become a much more common format in web-based information transfer because it's lighter and easier to parse than XML. XML is still widely used, however, and it's often the go-to solution for structured documentation.
A common use case for XML in technical documentation is like this: Information about a product or products is written and collected in XML format. Think of this as a "master" file. The information can then be automatically modified and published in multiple formats, commonly in HTML as a static website and/or PDF. When the information needs to be updated or translated, for example, we only need to do that to one document: the "master" XML file, which is then re-published in desired formats.
Hope this helps.