Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In XML, it doesn't matter what order the attributes are in. If you have some piece of XML processing code where it does matter, then I would suggest that code was buggy.</p> <p>From the XML spec <a href="http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-Attribute" rel="nofollow noreferrer">here</a>, note the phrase: "Note that the order of attribute specifications in a start-tag or empty-element tag is not significant".</p> <p>In answer to your specific question on whether you can enforce a certain order, I don't believe so. I've never actually tried to do it (since it's unnecessary) but it seems unlikely the REXML people would waste time implementing such a non-feature :-). Since the key/value pairs are stored as a hash, their order is likely to be random (as far as you could tell from the alphabetic sequence of the keys).</p> <p>Of course, since Ruby comes with the source code for REXML, you could (if desperate) replace or augment the included copy with your own version (REXML2 ?).</p> <p>Since you're doing a simple puts, it's probably using the pretty formatter so check the start of the <code>write_element</code> code in <code>src/rexml/formatters/pretty.rb</code> where it performs the "<code>node.attributes.each_attribute do |attr|</code>" - you may find it's as simple as sorting that list before processing the elements.</p> <p>You may also want to suggest to the developers (see <a href="http://www.germane-software.com/software/XML/rexml/index.html#id2248285" rel="nofollow noreferrer">here</a> for the mailing list or <a href="http://trac.germane-software.com//rexml" rel="nofollow noreferrer">here</a> for bug reports and enhancement requests) that they make this an option in a future release but, if I were them, I'd simply say it was unnecessary.</p>
    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. 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