Learning XML

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Learning XML

Post by ampakine on Wed Jun 22, 2011 5:44 pm
([msg=58863]see Learning XML[/msg])

I just can't get my head around XML for some reason. I know HTML inside out but I'm struggling to get an understanding of what XML is. I learn best on the fly when I'm applying what I'm learning so can anyone recommend some kind of web site feature that can only be made with XML or that is a lot easier to make with XML.
ampakine
Experienced User
Experienced User
 
Posts: 65
Joined: Tue May 31, 2011 5:21 pm
Blog: View Blog (0)


Re: Learning XML

Post by Goatboy on Wed Jun 22, 2011 6:16 pm
([msg=58869]see Re: Learning XML[/msg])

Whereas HTML can define a web page, XML doesn't actually define anything beyond what you want. It's a little confusing, and I was in the same place you are, so I'll try my best to explain:

Let's say you want to build an application that holds employee information. You don't want to use a full-blown database, and you want to be able to read the employee records manually. You might set up something like this:

Code: Select all
<Employees>
    <00001>
        <Name>Eric Tyke</Name>
        <Salary>40000</Salary>
        <Position>Software Engineer</Position>
    </00001>
    <00002>
        <Name>Sarah Bronson</Name>
        <Salary>56000</Salary>
        <Position>Project Manager</Position>
    </00002>
    <00003>
        <Name>Khalid al-Wahal Aj-Dubeen Ma A'Salaama</Name>
        <Salary>100000</Salary>
        <Position>Fucking Pimp</Position>
    </00003>
</Employees>


In this case, the root node is called Employees, and it holds all the other info. The numbers (00001, 00002, 00003) are employee IDs, used to uniquely identify each employee. Inside that, we have the name, salary, and position. Each new "level" is indented over. Applications can parse this easily, just as humans can.

XML doesn't "do" anything as you can see, but rather describes and contains data. You could just as easily create a cookbook, library directory, or calendar with XML.
Assume that everything I say is or could be a lie.
1UHQ15HqBRZFykqx7mKHpYroxanLjJcUk
User avatar
Goatboy
Expert
Expert
 
Posts: 2819
Joined: Mon Jul 07, 2008 9:35 pm
Blog: View Blog (0)


Re: Learning XML

Post by zerobug on Thu Jun 23, 2011 7:26 am
([msg=58894]see Re: Learning XML[/msg])

I'm kind of in the same shoes as amp when it comes to XML. Are you saying that the main purpose of XML is to create easily accessible information for other programs to use?
User avatar
zerobug
New User
New User
 
Posts: 24
Joined: Tue Jun 07, 2011 10:41 am
Blog: View Blog (0)


Re: Learning XML

Post by Assassian360 on Thu Jun 23, 2011 7:33 am
([msg=58895]see Re: Learning XML[/msg])

zerobug wrote:I'm kind of in the same shoes as amp when it comes to XML. Are you saying that the main purpose of XML is to create easily accessible information for other programs to use?


Yes. As Goatboy said, it "describes and contains data".
Assassian360
Poster
Poster
 
Posts: 135
Joined: Sat Jun 26, 2010 1:37 am
Blog: View Blog (0)


Re: Learning XML

Post by ampakine on Fri Jun 24, 2011 9:07 am
([msg=58942]see Re: Learning XML[/msg])

Thanks a lot! I think I'm starting to get it now. So its kind of like a universal language for storing data and at the same time categorising the data so that any program will be able to correctly interpret the data so long as you tell it how to interpret the your custom tags. Whats still confusing me a bit though is why one would opt for XML over just storing the info in a database. I usually store me data in a database and use PHP + SQL to access it. Is XML just a superior way to do what I do with PHP/MySQL? I say superior because I'm guessing using these tags which can have attributes and be nested allows you to describe the data in a far more profound way than you could by placing the data into different fields of a database which only really have field names to differentiate them from every other field.

Have I got the right idea there or am I way off?
ampakine
Experienced User
Experienced User
 
Posts: 65
Joined: Tue May 31, 2011 5:21 pm
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests