View Full Version : My first (very simple) attempt at learning XML

07-08-2009, 09:19 PM
Hello! I am very interested in learning how to create XML data using XSLT, so after reviewing some of the information, I took a shot at my first XML dataset plus a corresponding schema. That being said, I am a total newb to XML and am sure there is something wrong with this. Before I do that, here was what I was trying to accomplish - something simple to start.

I wanted to create a script on a site that contained recent news items from a ficticious company. These items would be written by whomever runs the site. Since these would be updated frequently, I wanted to create an easy way to dynamically update the information while only coding the html once. That is why I want to use XML for it. At this point, the only way the information can get updated is through editing the xml file itself. Once I get better at it, I would like to create a form that will update the xml data in the xml file.

I realize there are already all sorts of things out there that create this functionality and that is fine, but remember, I am trying to learn XML here, so this is where I started. Here is my code:

The XML file:

<?xml version="1.0"?>

<news_item xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mysite.com news_item.xsd">
<teaser>Just some text here that is a teaser of the full news item</teaser>

The schema

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

<xs:element name="news_item">
<xs:element name="date" type="xs:string"/>
<xs:element name="teaser" type="xs:string"/>
<xs:element name="full_text" type="xs:string/>

Basically, what I need to know is 1.) If the syntax and structure is correct, and 2.) In the state that it is in now, can I start using code in my html to draw this info into the page and display it without any errors? Any tips on where to find simple code to allow me to simply pull this information into a div in my html page? Thanks.
I appreciate any feedback. Thanks!