Just because two things have tree-like structures, that doesn't mean it's always trivial to convert between them.

Example 1: some XML dialects (such as XHTML) attach significance to the order in which the elements occur; others (such as RDF/XML) do not; others (like Atom) treat order as significant in some places but not others. Generally speaking, filesystems do not assign any significance to the order elements occur in. A directory containing foo.txt and bar.txt, and another directory containing bar.txt and foo.txt are effectively the same thing. (And diff will certainly treat them the same.)

Example 2: Many XML dialects allow sibling elements to have the same tag name. Given the following XHTML:

<html> <head /> <body /> </html>

... it might seem obvious to create a top-level directory called html with subdirectories head and body. But then let's expand upon that XHTML...

<html> <head /> <body> <p>Foo</p> <p>Bar</p> </body> </html>

... and then the body directory needs to contain two subdirectories, each called p. I don't know of any filesystems that would allow this.

Example 3: filesystems typically have two types on entities: directories and files. XML trees have more: elements, attributes, text nodes, comments, and (admittedly rarely) processing instructions. So you decide you want to represent elements as directories, and attributes as files, how do you represent the rest?

OK, so these are problems which are not insurmountable, but mapping XML's structure to the filesystem is not a trivial exercise at all.

The original poster had a fairly simple problem: how to compare two XML files and get a list of only the differences they care about (e.g. whitespace differences might not be important).

Going the filesystem route, they've swapped one problem for two - now they have to perform a potentially complex mapping from XML to the filesystem, and then find a way to compare two directories and get a list of only the differences they care about.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re^2: comparing xml and producing informative output by tobyink
in thread comparing xml and producing informative output by jccunning

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.