Click to See Complete Forum and Search --> : Defining XML elements.


Mr Initial Man
09-08-2005, 06:13 PM
I'm writing an HTML tutorial, and one thing I thought of doing was creating pages that showed the actual HTML Coding. Because of the elements needed, I decided to use XML.

This is an HTML page that shows what I have in mind. (http://coachrandom.furtopia.org/tutorial/framesetcode.html)

This is the XML file I'm working with. (http://coachrandom.furtopia.org/tutorial/presentationframes.xml)


What I'm trying to figure out is how do I define the XML elements?

Charles
09-08-2005, 08:53 PM
You write a DTD.

Mr Initial Man
09-08-2005, 08:57 PM
Am I basically coming up with my own markup language, then?

Please understand, I have never used XML before. This is basically a crash course for me.

LiLcRaZyFuZzY
09-09-2005, 03:40 AM
you might want to read this-> http://www.w3schools.com/dtd/default.asp
and the other xml tutorials at w3schools

Charles
09-09-2005, 04:41 AM
Am I basically coming up with my own markup language, then?If I correctly understand you, then yes.

Mr Initial Man
09-09-2005, 09:36 AM
Thanks for the tutorials. When I've done the DTD, can I use CSS with it? Or is CSS for HTML only?

LiLcRaZyFuZzY
09-09-2005, 10:28 AM
Formatting XML with CSS is NOT the future of how to style XML documents. XML document should be styled by using the W3C's XSL standard!
it can however be done:
http://www.w3schools.com/xml/xml_display.asp

here is an xsl introduction:
http://www.w3schools.com/xml/xml_xsl.asp

and here is a more extensive tutorial on xsl
http://www.w3schools.com/xsl/xsl_languages.asp

Mr Initial Man
09-09-2005, 11:02 AM
Okay, this is my XML file so far:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE showcode SYSTEM "codeml.dtd">
<showcode>
<code>
<line>&lt;<name>!DOCTYPE HTML</name> <public>PUBLIC</public> <value>"-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"</value>&gt;</line>
<line>&lt;<name>html</name> <att>lang</att>=<value>"en"</value> <att>dir</att>=<value>"ltr"</value>&gt;</line>
<line>&lt;<name>head</name>&gt;</line>
<line>&lt;<name>title</name>&gt;Presentation&lt;<end>/</end><name>title</name>&gt;</line>
<line>&lt;<name>meta</name> <att>http-equiv</att>=<value>"Content-Type"</value> <att>content</att>=<value>"text/html; charset=iso-8859-1"</value>&gt;</line>
<line>&lt;<name>meta</name> <att>http-equiv</att>=<value>"content-script-type"</value> <att>content</att>=<value>"text/javascript"</value>&gt;</line>
<line>&lt;<name>meta</name> <att>http-equiv</att>=<value>"Content-Style-Type"</value> <att>content</att>=<value>"text/css"</value>&gt;</line>
<line>&lt;<name>meta</name> <att>name</att>=<value>"Author"</value> <att>content</att>=<value>"John-David Kraaikamp"</value>&gt;</line>
<line>&lt;<name>meta</name> <att>name</att>=<value>"Description"</value> <att>content</att>=<value>"HTML Tutorial"</value>&gt;</line>
<line>&lt;<name>meta</name> <att>name</att>=<value>"Keywords"</value> <att>content</att>=<value>"HTML, Tutorial, website, building"</value>&gt;</line>
<line>&lt;<name>link</name> <att>type</att>=<value>"text/css"</value> <att>rel</att>=<value>"stylesheet"</value> <att>href</att>=<value>"style.css"</value>&gt;</line>
<line>&lt;<end>/</end><name>head</name>&gt;</line>
<line>&lt;<name>frameset</name> <att>cols</att>=<value>"50%, 50%"</value>&gt;</line>
<line>&lt;<name>frame</name> <att>src</att>=<value>"./presentation1.html"</value> <att>name</att>=<value>"side1"</value>&gt;</line>
<line>&lt;<name>frame</name> <att>src</att>=<value>"./presentation2.html"</value> <att>name</att>=<value>"side2"</value>&gt;</line>
<line>&lt;<name>noframes</name>&gt;</line>
<line>&lt;<name>div</name> <att>id</att>=<value>"top"</value>&gt;</line>
<line>&lt;<name>h1</name>&gt;Presentation&lt;<end>/</end><name>h1</name>&gt;</line>
<line>&lt;<name>h2</name>&gt;How does it look?&lt;<end>/</end><name>h2</name>&gt;</line>
<line>&lt;<end>/</end><name>div</name>&gt;</line>
<line>&lt;<name>div</name> <att>id</att>=<value>"wrapper"</value>&gt;</line>
<line>&lt;<name>div</name> <att>id</att>=<value>"content"</value>&gt;</line>
<line>&lt;<name>p</name>&gt;In case you haven't noticed, &lt;<name>a</name> <att>href</att>=<value>"presentation3.html"</value>&gt;this page&lt;<end>/</end><name>a</name>&gt; and &lt;<name>a</name> <att>href</att>=<value>"presentation4.html"</value>&gt;this page&lt;<end>/</end><name>a</name>&gt; look quite different.&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<name>p</name>&gt;However, their &lt;<name>strong</name>&gt;coding&lt;<end>/</end><name>strong</name>&gt; is the same, except for one crucial difference: the page on the right has the following element removed from the head:&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<name>p</name> <att>class</att>=<value>"example"</value>&gt;<char>&amp;lt;</char>link type="text/css" rel="stylesheet" href="style.css"<char>&amp;gt;</char>&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<name>p</name>&gt;In all other ways, these pages are identicle, except for a slight discrepancy in some of the heading text.&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<name>p</name>&gt;This is why, when dealing with presentation, you ignore the defaults offered by the elements when it comes to presentation. To cite an earlier page, &lt;<name>cite</name>&gt;How it looks is a function of &lt;<name>em</name>&gt;presentation&lt;<end>/</end><name>em</name>&gt;. HTML is concerned with &lt;<name>em</name>&gt;structure&lt;<end>/</end><name>em</name>&gt;.&lt;<end>/</end><name>cite</name>&gt;&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<name>p</name>&gt;Now that we're dealing with presentation, you'll learn why the default styles of the elements aren't important.&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<name>p</name>&gt;Years ago (late 1990s, in fact), all presentation was handled by HTML itself. Elements such as &lt;<name>strong</name>&gt;&amp;lt;font&amp;gt;&lt;<end>/</end><name>strong</name>&gt;, &lt;<name>strong</name>&gt;&amp;lt;i&amp;gt; (italics)&lt;<end>/</end><name>strong</name>&gt;, &lt;<name>strong</name>&gt;&amp;lt;b&amp;gt; (bold)&lt;<end>/</end><name>strong</name>&gt;, and &lt;<name>strong</name>&gt;&amp;lt;u&amp;gt; (underline)&lt;<end>/</end><name>strong</name>&gt; were all used to control how the website looked. They're still in use today, though they are no longer needed.&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<name>p</name>&gt;However, that made for very large, clunky websites. Then, near the turn of the millenium, the World Wide Web Consortium started coming out with &lt;<name>strong</name>&gt;Cascading Style Sheets&lt;<end>/</end><name>strong</name>&gt;, which relieved HTML of the task of presentation.&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<name>p</name>&gt;In teaching you presentation, I'm going to show how to use &lt;<name>strong</name>&gt;Cascading Style Sheets&lt;<end>/</end><name>strong</name>&gt; (&lt;<name>strong</name>&gt;CSS&lt;<end>/</end><name>strong</name>&gt; for short) to control every aspect of your site's appearance.&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<name>p</name>&gt;By the way, the text in those two pages is from a latin essay. The last paragraph is the "Lorem Ipsum" text, a "dummy text" which has been used for centuries.&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<end>/</end><name>div</name>&gt;</line>
<line>&lt;<name>div</name> <att>id</att>=<value>"menu"</value>&gt;</line>
<line>&lt;<name>ol</name>&gt;</line>
<line>&lt;<name>li</name>&gt;&lt;<name>a</name> <att>href</att>=<value>"./index.html"</value>&gt;Main&lt;<end>/</end><name>a</name>&gt;&lt;<end>/</end><name>li</name>&gt;</line>
<line>&lt;<name>li</name>&gt;&lt;<name>a</name> <att>href</att>=<value>"./intro.html"</value>&gt;Introduction&lt;<end>/</end><name>a</name>&gt;&lt;<end>/</end><name>li</name>&gt;</line>
<line>&lt;<name>li</name>&gt;&lt;<name>a</name> <att>href</att>=<value>"./doctype.html"</value>&gt;Document Type Declaration&lt;<end>/</end><name>a</name>&gt;&lt;<end>/</end><name>li</name>&gt;</line>
<line>&lt;<name>li</name>&gt;&lt;<name>a</name> <att>href</att>=<value>"./html.html"</value>&gt;HTML Element&lt;<end>/</end><name>a</name>&gt;&lt;<end>/</end><name>li</name>&gt;</line>
<line>&lt;<name>li</name>&gt;&lt;<name>a</name> <att>href</att>=<value>"./head.html"</value>&gt;Head Element&lt;<end>/</end><name>a</name>&gt;&lt;<end>/</end><name>li</name>&gt;</line>
<line>&lt;<name>li</name>&gt;&lt;<name>a</name> <att>href</att>=<value>"./body.html"</value>&gt;Body Element&lt;<end>/</end><name>a</name>&gt;&lt;<end>/</end><name>li</name>&gt;</line>
<line>&lt;<name>li</name>&gt;&lt;<name>a</name> <att>href</att>=<value>"./semantics.html"</value>&gt;HTML Semantics&lt;<end>/</end><name>a</name>&gt;&lt;<end>/</end><name>li</name>&gt;</line>
<line>&lt;<name>li</name>&gt;&lt;<name>span</name>&gt;Presentation&lt;<end>/</end><name>span</name>&gt;&lt;<end>/</end><name>li</name>&gt;</line>
<line>&lt;<name>li</name>&gt;&lt;<name>a</name> <att>href</att>=<value>"./css.html"</value>&gt;Cascading Style Sheets&lt;<end>/</end><name>a</name>&gt;&lt;<end>/</end><name>li</name>&gt;</line>
<line>&lt;<end>/</end><name>ol</name>&gt;</line>
<line>&lt;<end>/</end><name>div</name>&gt;</line>
<line>&lt;<end>/</end><name>div</name>&gt;</line>
<line>&lt;<name>p</name>&gt; &lt;<name>a</name> <att>href</att>=<value>"http://validator.w3.org/check?uri=referer"</value>&gt;&lt;<name>img</name> <att>src</att>=<value>"http://www.w3.org/Icons/valid-html401"</value> <att>alt</att>=<value>"Valid HTML 4.01 Frameset"</value> <att>height</att>=<value>"31"</value> <att>width</att>=<value>"88"</value>&gt;&lt;<end>/</end><name>a</name>&gt;&lt;<end>/</end><name>p</name>&gt;</line>
<line>&lt;<end>/</end><name>noframes</name>&gt;</line>
<line>&lt;<end>/</end><name>frameset</name>&gt;</line>
<line>&lt;<end>/</end><name>html</name>&gt;</line>
</code>
<line>
<link target="./presentation.html">Back to Presentation</link>
</line>
</showcode>

This is my DTD:


<!ELEMENT showcode (#PCDATA|code|line|name|public|att|value|char|end|link)*>
<!ELEMENT code (#PCDATA)>
<!ELEMENT line (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT public (#PCDATA)>
<!ELEMENT att (#PCDATA)>
<!ELEMENT value (#PCDATA)>
<!ELEMENT char (#PCDATA)>
<!ELEMENT end (#PCDATA)>
<!ELEMENT link (#PCDATA)>
<!ATTLIST link target CDATA #REQUIRED>

Here's what I intend to do with my elements:

<showcode> would be sort of like an <html> element, <code> would be my equivalent as a body element. <name>, <public>, <att>, <value>, <char>, and <end> should all work like <span> elements, but each is styled differently.

<line> is supposed to be like a cross between a <p> element and the <li> element for a numbered list (basically, every line would be numbered), and <link> is intended to be like an <a> element. Do I define how these work in XSL or the DTD?

LiLcRaZyFuZzY
09-09-2005, 11:42 AM
did you read the XSLT tutorial?
http://www.w3schools.com/xsl/default.asp

The style is defined in a separate file, the xsl file
and linked to in the xml like this
<?xml-stylesheet type="text/xsl" href="style.xsl"?>

Mr Initial Man
09-09-2005, 12:33 PM
I think I'm getting somewhere, because already I'm in trouble. >.>

My XSL document. (http://www.coachrandom.furtopia.org/tutorial/xml/code.xsl)

My DTD:
<!ELEMENT showcode (#PCDATA|code|line|name|public|att|value|char|end|link)*>
<!ELEMENT code (#PCDATA)>
<!ELEMENT line (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT public (#PCDATA)>
<!ELEMENT att (#PCDATA)>
<!ELEMENT value (#PCDATA)>
<!ELEMENT char (#PCDATA)>
<!ELEMENT end (#PCDATA)>
<!ELEMENT link (#PCDATA)>
<!ATTLIST link target CDATA #REQUIRED>

My XML document (http://www.coachrandom.furtopia.org/tutorial/xml/presentationframes.xml)

For some reason, it's only showing the first line. What did I do wrong?

LiLcRaZyFuZzY
09-09-2005, 01:16 PM
don't have much time right now, but i'll take a look at it when i come back

good luck

LiLcRaZyFuZzY
09-10-2005, 03:14 AM
here you might wanna try this xsl

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html lang="en" dir="ltr">
<head>
<title>Frameset Coding</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Author" content="John-David Kraaikamp" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta name="Content-Style-Type" content="text/css" />
<meta name="Description" content="HTML Tutorial" />
<meta name="Keywords" content="HTML, Tutorial, website, building" />
<link type="text/css" rel="stylesheet" href="code.css" />
</head>
<body>
<xsl:for-each select="showcode/code/line">
<p><xsl:value-of select="line"/></p>

<strong class="name"><xsl:value-of select="name"/></strong>
<strong class="att"><xsl:value-of select="att"/></strong>
<strong class="end"><xsl:value-of select="end"/></strong>
<strong class="public"><xsl:value-of select="public"/></strong>
<strong class="char"><xsl:value-of select="char"/></strong>
<em><xsl:value-of select="value"/></em>
<a><xsl:value-of select="link"/></a>

</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


the not-displaying was just an XPath error
on this line

<xsl:for-each select="showcode/code/line">


something weird comes up, no indentation, no spaces between attributes, but the whole does show up

Mr Initial Man
09-10-2005, 06:40 AM
Oy. I noticed...

I've been working on a DTD, but that doesn't seem to affect anything, unless I'm doing it completely wrong.