5

Starting a new project and was planning on storing all of my web content in XML. I do not have access to a database so this seemed like the next best thing. One thing I'm struggling with is how to structure the XML for links (which will later be transformed using XSLT). It needs to be fairly flexible as well. Below is what I started with, but I'm starting to question it.

<links>
    <link>
        <url>http://google.com</url>
        <description>Google</description>
    <link>
    <link>
        <url>http://yahoo.com</url>
        <description>Yahoo</description>
        <links>
            <url>http://yahoo.com/search</url>
            <description>Search</description>
        </link>
    <link>
</links>

That should get transformed into

Google Yahoo Search

Perhaps something like this might work better.

<links>
    <link href="http://google.com">Google</link>
    <link href="http://yahoo.com">Yahoo
        <link href="http://yahoo.com/search">Search</link>
    </link>
</links>

Does anyone perhaps have a link that talks about structuring web content properly in XML?

Thank you. :)

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
Mike
  • 139
  • 1
  • 6
  • 1
    @Mike: Your second approach has problematic intermixing of text nodes with element nodes - it's not `"Yahoo"`, but actually `"Yahoo\n\t\t"`. This is quite common in HTML but should be avoided in data-centric XML for the can of worms that it is. – Tomalak Mar 31 '10 at 16:34

2 Answers2

2

I would be tempted to use something like:

<links>
  <link url="http://google.com" text="Google"/>
  <link url="http://yahoo.com" text="Yahoo">
    <links>
      <link url="http://yahoo.com/search" text="Search"/>
    </links>
  </link>
</links>

(although the inner <links> is optional and could be removed so you had links/link/link)

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
0

Are you sure about using XML as a database? See: When would I use XML instead of SQL?

“XML is not a database. It was never meant to be a database. It is never going to be a database. Relational databases are proven technology with more than 20 years of implementation experience. They are solid, stable, useful products. They are not going away. XML is a very useful technology for moving data between different databases or between databases and other programs. However, it is not itself a database. Don't use it like one.“

Community
  • 1
  • 1
compie
  • 10,135
  • 15
  • 54
  • 78
  • While I agree, the problem is that I do not have access to any types of database for this project. SQLLite isn't even an option either. Only reason I resorted to XML is to quickly be able to transform the file with XSLT. I want to stay away from having every web page a static file with content. – Mike Mar 31 '10 at 16:44