General Java Questions

Hi there,

Taking a break from game development, I decided to learn more on the side of applications and tools using Java. I have a few questions that a few colleagues and I discussed today.
1.) What are the uses of using xml files with java? Like, the main purposes…
2.) How could you create a serial or ID based xml, that holds information as it is entered. Basically, assigning a callable ID for a profile (with first and last name, address, etc. - for example).
3.) What are some cool things you can do with xml and java?

Thanks!

  • A

Google. Wikipedia. You will find better answers faster.

Here’s a sample of uses:
http://www.informit.com/library/content.aspx?b=STY_XML_21days&seqNum=15

Why such an interest in XML?

Yea, I’ve been using Google and have found many answers. This isn’t really for an answer, but more opinions… per se. =)
& I’m not sure really, I just find reading/writing data interesting at the moment. :slight_smile:

Thank you!

then, for the sake of cute fluffy bunnies, focus on a sane, straightforward format like json.

I agree JSON is nice, but coming from an HTML background, I think XML is easier to conceptualize :slight_smile: But that’s must me :slight_smile:

CopyableCougar4

The difference between the two is like the difference between C# and Java.

json is pretty cool because it serializes directly into js :smiley:
i use it for my payload system between frontend and backend apps, and also across backend services

For pure human readable data storage and transfer json is great. As a markup language xml might be better since it allows for mixed content. As a configuration language, xml also has it’s merrits, because of the widespread completion and documentation support in IDEs based on schemas. Hopefully json-schema catches up there soon…

A map in JSON:


{
   water: 'h2o',
   oxygen: 'o2',
   glucose: 'c6h12o6'
}

A map in XML:


<map>
   <entry key="water" value="h2o"/>
   <entry key="oxygen" value="o2"/>
   <entry key="glucose" value="c6h12o6"/>
</map>

A map in XML:


<map>
   <entry>
      <key>water</key>
      <value>h2o</value>
   </entry>
   <entry>
      <key>oxygen</key>
      <value>o2</value>
   </entry>
   <entry>
      <key>glucose</key>
      <value>c6h12o6</value>
   </entry>
</map>

A map in XML:


<map>
   <key>water</key>
   <value>h2o</value>

   <key>oxygen</key>
   <value>o2</value>

   <key>glucose</key>
   <value>c6h12o6</value>
</map>

There is a right way to structure your XML graph, but everybody uses their own style, and worse… is inconsistent across documents or in the very same document.

:stuck_out_tongue:

You forgot the “maven-way”:


<map>
   <water>h2o</water>
   <oxygen>o2</oxygen>
   <glucose>c6h12o6</glucose>
</map>

But as I said - xml is a markup language and using it as a configuration language only makes sense when paired with a schema to get code-completion and inline-documentation support.

<map>
  <![CDATA[
  {
     water: 'h2o',
     oxygen: 'o2',
     glucose: 'c6h12o6'
  }
  ]]>
</map>

there is no right way to structure xml. it’s either valid or not.

You’re being unfair to XML. There is no “right way to structure a map in XML” because XML is not a language, it is a metalanguage for defining new grammars. In many grammars based on XML, there is a “right (and only) way to structure a map”.

[quote]there is no right way to structure xml. it’s either valid or not.
[/quote]
Correction: XML is either well-formed or not. If a document is valid, that means it conforms to schema of some kind, which will define how to do the map.

And anyway, you can define maps in multiple ways in JSON, just like XML:


[
    {
        "key": "name",
        "value": "ags"
    },
    {
        "key": "location",
        "value": "earth"
    },
    {
        "key": "nature",
        "value": "nice"
    }
]

Ofcourse you can abuse JSON, but it’s very, very rarely done, as opposed to XML where it’s a shitstorm every single day.

I know, managing XML schemas is a big part of my day job. I generate them from a DSL to keep them consistent.

Anyway Riven, your JSON example ain’t valid :slight_smile: You need some irritating quotes around the keys.

I hope you love your dayjob, I’d be outader in a split second. :slight_smile:

I know, right? I was lazy. And I prefer parsers/exporters that allow this lenient notation. :persecutioncomplex:

I just make up the rules and build tools for people so that it’s not possible for them to break the rules. Like Newspeak, really.

The fact that you prefer your form of JSON over the form of JSON supported by my parser is exactly why we need XML.

You seem to compare [XML + schemas] to [JSON], while we’re talking about [XML] vs [JSON], throwing syntax rules (quotes or not) into the mix, while that is a totally different issue: standards. Whether something can be parsed or not does not in any way relate to schemas.

Both XML and JSON can have schemas to validate them, or to provide auto-completion.

You don’t see JSON schemas in the wild (well, I never heard of them…) and that’s mainly because JSONs explicit support for basic primitives (boolean, double), null, strings and data structures (arrays, maps) gently push you a ‘common’ direction of organizing your data, which means you don’t really need schemas so much. But if the need arises, nothing prevents you from slapping a schema on your JSON, or any other format.

Having said that, I think we overstayed our welcome in this thread :persecutioncomplex: