I'm confused on what XML is used for?

Discussion in 'XML & RSS' started by StormForum, Feb 23, 2007.

  1. #1
    Okay, my friend keeps telling me "XML defines the content" and I don't understand, after reading many tutorials about XML, what XML is used for, and I don't understand it. Can anyone explain to me what XML is used for? I'm very confused. Thanks :).
     
    StormForum, Feb 23, 2007 IP
  2. sadcox66

    sadcox66 Spirit Walker

    Messages:
    496
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    XML is used to exchange information between different applications.
    Let us say you were building a shopping cart on your website.
    You would need to communicate with.
    a.) FedEx/ UPS or other shipping company. What you do is you create an XML packet that contains Package Weight( in lb or kg) , give your dimenstions and source and destination address and send it to the shipping company and they send back an XML packet with the cost to ship the package by 1-day, 2-day, ground., you parse the XML and display it to your prospective customer.
    b.) If you have PayPal integration you can use XML to get instant notifications that you have got paid. Other payment processors do provide similar facility.
    c.) If your building an Amazon Store on the web you could download the appropiate category from Amazon in XML and display the products on your website. You can do every hour to get the latest prices.

    i.) In all of these cases we do not care what database (Oracle/postgres/MsSql/other) runs on UPS/FedEx/Amazon.
    ii.) We do not care about the structure of the Database in the backend. If Amazon changes their database format - Usually we would not be affected., if amazon introduced a new category or product and you can automate your website to display any new categories - essentially amazon controls what is displayed on your site - if you want.
    iii.) If UPS introduces, courier service then you will see such an option in your shipping options


    The above is the basic idea - and the direction we want to go - but when you get into the nitty gritty of the matter and begin programming/parsing/error handling can become complicated very quickly
     
    sadcox66, Feb 23, 2007 IP
  3. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #3
    XML is used for whatever you want

    XML is merely a 'framework', which enables you to define the way to store or transmit data. It allows you to give structure to data.

    For example. I could make an application that sends receipts in a text file, and a reporting tool that parses that text file for string patterns on specific lines. Very unreliable.

    Or I could define the receipts in an XML format, and just parse the nodes I want.

    Great for APIs!
     
    frankcow, Feb 23, 2007 IP
  4. MattD

    MattD Peon

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    One of the "Ah-ha!" moments for me with XML was when I realised this: XML doesn't actually do anything.

    Its just a way to organise data really, with the intention being that it is easy to understand and use by programmers and applications.

    I came at it from a web design/development angle having had someone start ranting about it being the future of the web many years ago...compared to HTML it seemed really pointless :D
     
    MattD, Feb 24, 2007 IP
  5. stocknsurf

    stocknsurf Peon

    Messages:
    121
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    As jerry seinfield once told ...what is your show all about? He told it is about nothing. Similarly XML is nothing. OK...OK, it is something, but really not anything!

    As others have told, XML is a standard to represent data and exchange data that strictly confirms to a agreed format.

    OK, let us take a simple example here. For example say you want to write an letter to a friend (in the olden days - who writes letter anymore !) How do you write it? It is something like
    -----------------------------------------------------------------------
    From,
    StormForum

    To
    StormForum's friend

    Subject: How are you doing

    Message: Just wanted to know more about XML! Write back.
    ----------------------------------------------------------------

    OK, now you finish writing the letter, put it in an envelope and mail it, right? Your friend at the other end fortunately knows how to read your letter. So he can automatically understand it, even though both of you didn't talk before hand agreeing on a common format. OK, that is what human beings do!!! But alas, computers can't do that. Let us say now rather you were a MySQL database and you friend were a Oracle database and you want to exahange information. You can't simply write the above letter. The Oracle database will basically reject your message since it can't understand any of the MySQL format.

    So what do you do? That is where XML comes in.

    So what you do is agree with the other party before hand that this is the format of the letter you will write and you provide them the rules. Once they have agreed to that format, you say that I will send the information. This agreed upon format is called DTD - Document Type Definition. i.e. you define a document type and lay out the format, that has to be agreed by the other party which wants to receive your information.

    So in the above example say you tell your friend that you will write a letter that will contain these tags (since otherwise he can't translate!). Or in other words you provide this DTD to your friend.

    <!DOCTYPE LETTER [<!ELEMENT LETTER (FORMAT+)>
    <!ELEMENT From (#PCDATA)>
    <!ELEMENT To (#PCDATA)>
    <!ELEMENT Subject (#PCDATA)>
    <!ELEMENT Message (#PCDATA)>
    ]>

    Now your friend knows how to translate the data you send, since it will strictly confirm to a particular format that both of you have agreed upon. OK, now you write the letter

    <From>StormForum</From>
    <To>My friend</To>
    <Subject>Hi, how are you</Subject>
    <Message>Tell me more about XML!</Message>

    You are done with writing. Now you send it. When your friend receives it, he uses the template you provided before to translate the data back to the format he wants. Then it is up to your friend to do whatever he wants to do with the data.

    So in the above scenario, instead of you and your friend, substitute two computing elements (it can be anything) that wants to exchange data. This is how then can achieve it.

    Sorry for the long one. I try my best :). Hope this helps. Good luck.
    BTW good explanation SADCOX66
     
    stocknsurf, Feb 26, 2007 IP
  6. future

    future Banned

    Messages:
    376
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    xml in blogging is consider to share your new post with other in quick and help to make traffic!
     
    future, Mar 2, 2007 IP