Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Is there any reason why</p> </blockquote> <p>Taking your question philosophically, SGML <em>did</em> allow <code>&lt;/&gt;</code> close tags. There was debate about allowing this into the XML standard. The reasoning for rejecting it was that omitting the names from end tags would sometimes result in less readable XML. So, that is a "reason why".</p> <p>It's hard to beat existing text compression rates, but one advantage of your "compression" scheme is the XML remains <i>human readable</i> on the wire. Another advantage is that if you have to enter XML by hand (e.g. for testing), it's a (minor) convenience to not have to close end tags. That is, it's more <i>human writable</i> than standard XML. I say "minor", because most editors will do string completion for you (e.g. ^n and ^p in vim).</p> <p><strong>To strip the close tags</strong>: simplest is to use something like this: <code>s_&lt;/[a-zA-Z0-9_$]+&gt;_&lt;/&gt;_</code> (that's not the right QName regex, but you get the idea).</p> <p><strong>To add them back</strong>: you need a special parser, because SAX and other XML parsers won't recognize this (as it's not "XML"). But the (simplest) parsing just needs to recognize open tag names and close tag names.</p> <pre><code>have a stack. scan the XML, and output it, as-is. if you recognize an open tag, push its name. if you recognize close tag, pop to get its name, and insert that in the output (you can do this even when there is a proper close tag). </code></pre> <p>BTW (in response to a comment above), this works because in XML a close tag can only ever correspond to the most recent open tag. Same as nested parentheses.</p> <p>However, I think you're right, that someone has surely done this already. Maybe check Python or Perl repositories?</p> <p>EDIT: You can further omit trailing <code>&lt;/&gt;</code>, so your example becomes (when the parser sees EOF, it adds close tags for whatever's left on the stack):</p> <pre><code>&lt;person&gt; &lt;firstname&gt;Joe&lt;/&gt; &lt;lastname&gt;Plumber </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload