| Author |
Message |
bdi Nobody
Joined: 21 Oct 2004 Posts: 1646 Location: Chicago
|
Posted: Sat Dec 17, 2005 12:11 pm Post subject: Why Use XML? |
|
|
http://itpov.com/item-13.html
Just added an article to my blog on why you would want to use XML. It has come up several times and I figured it has come up several times, so it was worth writing up. |
|
| Back to top |
|
 |
theraje Cap'n Arr!
Joined: 22 Oct 2004 Posts: 262
|
Posted: Sun Dec 18, 2005 4:12 am Post subject: |
|
|
Nice topic to write about, Josh. I think using XML is an excellent way to do a number of things... now I'll concrete reasons to tell people why.  |
|
| Back to top |
|
 |
natriss102 Bushi
Joined: 23 Oct 2004 Posts: 256 Location: The plains of Kansas
|
Posted: Sun Dec 18, 2005 2:53 pm Post subject: |
|
|
| Ok, ok, so the w3schools tutorial gave an overview on it's synatx and uses, but how can you integrate it into a webpage? I never picked up on how to read invididual items from the xml file. |
|
| Back to top |
|
 |
Ankou Spam Mod
Joined: 22 Oct 2004 Posts: 1201 Location: Wisconsin
|
Posted: Sun Dec 18, 2005 6:26 pm Post subject: |
|
|
Most of the web languages have methods for parsing XML data, or you can always make use of CSS and/or XSL/XSLT/XPath to display/transform the XML file.
java script -- you can explore this more but take a peek at the W3Schools example: http://www.w3schools.com/xml/tryit.asp?filename=xml_note
PHP - Take a look at the manual - http://us2.php.net/xml
And if you're working with Flash/ActionScript it's pretty simple there as well: http://www.actionscript.org/tutorials/intermediate/XML/index.shtml (BTW I just recently deleted a good ActionScript/XML tutorial from my bookmarks - guess that'll teach me for cleaning up the massive list of bookmarks I thought I'd never use again) |
|
| Back to top |
|
 |
natriss102 Bushi
Joined: 23 Oct 2004 Posts: 256 Location: The plains of Kansas
|
Posted: Sun Dec 18, 2005 6:55 pm Post subject: |
|
|
Which way is easiest?
XSLT looks pretty good |
|
| Back to top |
|
 |
bdi Nobody
Joined: 21 Oct 2004 Posts: 1646 Location: Chicago
|
Posted: Sun Dec 18, 2005 10:27 pm Post subject: |
|
|
| XSLT is easy and made specifically for that, but not all browsers support it. Using the server side functions is usually the safest route right now. |
|
| Back to top |
|
 |
natriss102 Bushi
Joined: 23 Oct 2004 Posts: 256 Location: The plains of Kansas
|
Posted: Sun Dec 18, 2005 10:30 pm Post subject: |
|
|
ok
well the php parser is WAY over my head (unless someone would like to explain it, but I don't want to put you throught that)
i don't know enough java script to make it worthwhile
css looks like about the only route for me |
|
| Back to top |
|
 |
bdi Nobody
Joined: 21 Oct 2004 Posts: 1646 Location: Chicago
|
Posted: Sun Dec 18, 2005 10:44 pm Post subject: |
|
|
You can go with the XSLT. I forget what it works in and what it doesn't. If you want to use the PHP parser, don't lose any sleep over it. Just use someone else's premade class.  |
|
| Back to top |
|
 |
bdi Nobody
Joined: 21 Oct 2004 Posts: 1646 Location: Chicago
|
Posted: Sun Dec 18, 2005 10:58 pm Post subject: |
|
|
http://www.w3schools.com/xsl/xsl_browsers.asp
Here's an updated list of XSLT browser support. Looks like the "gaping hole" is in IE 5. Depending on your use, it might be well worth it to say "oh well" to those people. I mean, you can't depend on everyone being bleeding edge, but how long has IE 6 been out now? A long time. |
|
| Back to top |
|
 |
Ankou Spam Mod
Joined: 22 Oct 2004 Posts: 1201 Location: Wisconsin
|
Posted: Mon Dec 19, 2005 1:23 pm Post subject: |
|
|
| bdi wrote: | If you want to use the PHP parser, don't lose any sleep over it. Just use someone else's premade class.  |
Exactly... if you're looking to work with PHP and XML then there's no need to reinvent the wheel. Do a search for PHP XML class or maybe even PHP XML tutorials and see what turns up.
Either way you'll have some code to play around with to leran from. Modify it, see what happens - before you know it what you thought was over your head is starting to look pretty simple. |
|
| Back to top |
|
 |
natriss102 Bushi
Joined: 23 Oct 2004 Posts: 256 Location: The plains of Kansas
|
Posted: Mon Dec 19, 2005 1:24 pm Post subject: |
|
|
I am not even sure what the php parser is supposed to do.
Do you include the php parser along with xml file on a desired page?
What is the output going to look like? |
|
| Back to top |
|
 |
Ankou Spam Mod
Joined: 22 Oct 2004 Posts: 1201 Location: Wisconsin
|
Posted: Mon Dec 19, 2005 1:38 pm Post subject: |
|
|
Let's say you had a simple list of website addresses, the site name and maybe even a ranking system for the sites all stored in an XML file. The idea is to use this on your website in order to display each link by it's rank.
On your main page you're only going to show the top 5 but on another page you'll show the whole list.
With PHP you put in your code to get the information from the file and then display either the top 5 highest ranking websites or the full list. The XML file can sit in any directory your choose as long as PHP can get to it.
So the PHP code can be used in any PHP file you want, the XML file can sit anywhere as long as PHP can get to it and use it, and the output.... well that would be us to you as well.
Think for a minute instead of XML you were working with a flat file that looked something like:
Programmer's Corner*http://programmers-corner.com/*10
Yahoo!*http://www.yahoo.com/*9
and so on...
That's the site name, address and rank - all stored in a file. Now you know how to open that file, read the contents line by line, parse that data and then use it to be displayed...
Well it's the same with XML except that the data would be store a bit differently and parsing it would use different functions.
| Code: | <?xml version="1.0" encoding="ISO-8859-1"?>
<websites>
<item>
<name>Programmer's Corner</name>
<address>http://programmers-corner.com/</address>
<rank>10</rank>
</item>
<item>
<name>Yahoo!</name>
<address>http://www.yahoo.com/</address>
<rank>9</rank>
</item>
</websites> |
That's just a simple XML file. So with PHP you can parse the data and store everything in an array (or arrays) so that you can get the data later and display it in any way you want.
Site title with link - rank
Site title (link) - rank
etc..
It's up to you really... |
|
| Back to top |
|
 |
Moto Grasshopper
Joined: 22 Feb 2007 Posts: 4
|
Posted: Mon Feb 25, 2008 8:47 am Post subject: |
|
|
Here's my question, I'm trying to parse an xml document, that includes optional fields, <location> and <description>.
If the user doesn't fill in those fields, only the closing tag shows up in the xml document, which unceremoniously dumps the java script I'm running against it.
I'm very much a novice at this, and am using the w3schools examples to get started.
Has anyone run into this, and how did you work around it if so?
Thanks.
The artist formerly known as OAG |
|
| Back to top |
|
 |
Ankou Spam Mod
Joined: 22 Oct 2004 Posts: 1201 Location: Wisconsin
|
Posted: Tue Feb 26, 2008 10:39 pm Post subject: |
|
|
Where are you getting the XLM file from? I'm wondering why it would just be putting the closing tag in there...
If you have code that generates that XML file could you post it? Otherwise you may want to have your script first check the file for situations like that... make sure each closing tag has an opening tag. |
|
| Back to top |
|
 |
WannaBe Wiggles
Joined: 22 Oct 2004 Posts: 714 Location: CA
|
Posted: Thu Feb 28, 2008 5:37 am Post subject: |
|
|
A closing tag like: </tag> or an inline tag? <tag />
If the tag is optional in the xml scheme, then it doesn't need to have that tag at all in the xml contents if that xml file wants to use the default contents for that tag (which would be handled by the application to set the defaults). |
|
| Back to top |
|
 |
|