News for hackers. Stuff that matters.
Re:XML is almost always misused by mpweiher on Tuesday October 29, 2019 @04:21PM (#21391553)
Hmm...somewhat disagree with the "correct" way to express a dictionary. I prefer:

   <root>
      <Name>John</Name>
      <City>London</City>
   </root>
Removes one level of indirection, XML already has keys.
Re:XML is almost always misused by Sharlin on Tuesday October 29, 2019 @04:34PM (#21391676)
This is not a dictionary, it’s a record. Unfortunately this fairly fundamental distinction has been thoroughly muddied by certain languages that want to use associative arrays for everything.
Re:XML is almost always misused by mpweiher on Tuesday October 29, 2019 @04:41PM (#21391754)
Hmm...you seem to be mapping programming language concepts 1:1 to XML. That is a mistake.
Re:XML is almost always misused by Sharlin on Tuesday October 29, 2019 @04:44PM (#21391796)
I'm not the one doing that. People using XML as something else than a document markup language are. Which is what the article author is complaining about. But if you really want to do that, then at least do it properly. Record fields have predefined names, just like XML elements have predefined names. Dictionary keys can be arbitrary, like XML text nodes or attribute values but emphatically not element or attribute names, unless your "XML" is actually just tag soup.
Re:XML is almost always misused by progval on Tuesday October 29, 2019 @04:28PM (#21391611)
That's not a good way to express a dictionary because it does not allow arbitrary strings as key names.

It's also not a good example of XML, because XML schemas should have a fixed list of tag names.

Re:XML is almost always misused by sorenjan on Tuesday October 29, 2019 @05:13PM (#21392094)
But the starting point in the example was

    <item name="name" value="John" />  
    <item name="city" value="London" />  
where the key names are used as attributes, so it wouldn't work with arbitrary key names either, right?
Re:XML is almost always misused by progval on Tuesday October 29, 2019 @05:22PM (#21392189)
It would work (kind of); most XML parsers/generators would take care of escaping and unescaping quotes; but there's no way in the XML spec to escape characters in tag names.
Re:XML is almost always misused by mpweiher on Tuesday October 29, 2019 @04:38PM (#21391716)
XML allows arbitrary strings as key names just fine.
Re:XML is almost always misused by progval on Tuesday October 29, 2019 @04:40PM (#21391740)
No, you can't have quotes, spaces, etc., because with GGP's scheme it would be a tag name, and these are invalid in tag names.
Re:XML is almost always misused by jimktrains2 on Tuesday October 29, 2019 @04:31PM (#21391648)
The main issue I see with that is that if it's a true dictionary, then those elements will constantly be different, which is weird.

Now, if we're just encoding a dictionary that's an already an encoding of an object, then yeah, let's just encode the object directly like you are above.

Re:XML is almost always misused by Felk on Tuesday October 29, 2019 @04:29PM (#21391627)
Which works if you either expect a dictionary with a predefined set of fields (which isn't really a dictionary then), or parse your xml in a way that handles arbitrary tags. For a generic dictionary the shown approach is still the way to go, if you really want to use XML for that.
Re:XML is almost always misused by mpweiher on Tuesday October 29, 2019 @04:39PM (#21391721)
XML parsers generally allow arbitrary tags.
Re:XML is almost always misused by benibela on Tuesday October 29, 2019 @04:44PM (#21391795)
That is definitely the best to use with xpath
Re:XML is almost always misused by srott on Tuesday October 29, 2019 @04:31PM (#21391642)
you've just invented plist, wonder if it can be validated by a schema..

  <dict> 
        <key>CFBundlePackageType</key>
        <string>FMWK</string>
        <key>CFBundleShortVersionString</key>
        <string>4.8</string>
...
Re:XML is almost always misused by progval on Tuesday October 29, 2019 @04:35PM (#21391686)
No, GP didn't. They use tag names as keys.

But you answer your question, yes this format can be expressed with XML-Schema:

  <xsd:element name="dict">
    <xsd:complexType>
      <xsd:sequence minOccurs="0" maxOccurs="unbounded">
        <xsd:element name="key" type="xsd:string" />
        <xsd:choice>
          <xsd:element name="string" type="xsd:string" />
          <xsd:element name="integer" type="xsd:integer" />
          <!-- etc. -->
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
Re:XML is almost always misused by spiralx on Friday November 01, 2019 @12:33PM (#21420671)
Or in RELAX-NG compact :)

    grammar {
      start = Dict
      Dict = element dict { DictItem* }
      DictItem =
        element key { text },
        (element string { text } | element number { xsd:integer })
    }