Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Using XML to split content [warning newbie lurks here]

Reply
Thread Tools

Using XML to split content [warning newbie lurks here]

 
 
build@datafast.net.au
Guest
Posts: n/a
 
      04-12-2005
G'day All,
I hope you folk are tolerant of newbies who don't express themselves
well, cause I'm one of those. If not please excuse this and move on.

I'm designing a small web site and while I thought I'd done a good job
of planning the project and learning the required skills I've now
discovered a hole in my plan.

I'm using a template like php script to the build pages.
I'm also using php sessions to authenticate access to members and
guests.
The content component is in xhtml.

Now I'm at the testing stage, I've started to prepare a few of the
xhtml files and realised a lot of the content is an amalgum of 'guest'
and 'member' stuff. I don't really want to have a separate page for
each class of user, with largly identical content.

I've read all the W3C tutorials on XML, XSLT, etc. I'm quite excited
about the possible uses of XML applied to my current problem and a
myriad of other applications (such a simple idea, but so bloody
useful). However my mind is currently a potpourri of half baked ideas.
I'm failing to get a proper grasp on exactly how to utilise xml.

I'm wondering if I could modify the xhtml files to xml and use tags to
decide what to display?

i.e. the stuff enclosed by the <member> tag should only be written to a
member session.

<h1>My Page</h1>
<p><em>16/03/2005</em><br />
Sorry, we were offline for a few hours this morning, someone tripped
over the extension lead.
</p>
<member>
<p>
<strong><em>03/03/2005</em>
<br />
Barton Mawer WINS at the Australian Grand Prix (<a
href="lindsay/bartonmawer.htm" target="main">more</a>).</strong>
</p>
</member>

My questions are:
1) Am I on the right track? Is XML the answer to my problem?
2) Is there an easy way of separating the content without having to
parse all the xhtml tags as well as the xml tags???
3) If so, I need to get a better understanding of XML, what is your
suggested next step after reading the W3C tutorial?

If this is an inappropriate place for this post could some kind soul
please point me in the right direction?

apologies in advance as I realise I have not phrased the question well
(cringe), your tolerance would be greatly appreciated.

Thanking you in anticipation,
build

 
Reply With Quote
 
 
 
 
Soren Kuula
Guest
Posts: n/a
 
      04-13-2005
Hi,

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> G'day All,
> I hope you folk are tolerant of newbies who don't express themselves
> well, cause I'm one of those. If not please excuse this and move on.


Grrrrrrrrrrrrrrrrrrrrrrrrrrrr.. BARK BARK! No, welcome, really

> I'm designing a small web site and while I thought I'd done a good job
> of planning the project and learning the required skills I've now
> discovered a hole in my plan.
>
> I'm using a template like php script to the build pages.
> I'm also using php sessions to authenticate access to members and
> guests.
> The content component is in xhtml.


Good idea -- it's better to work on with power tools than html.

> Now I'm at the testing stage, I've started to prepare a few of the
> xhtml files and realised a lot of the content is an amalgum of 'guest'
> and 'member' stuff. I don't really want to have a separate page for
> each class of user, with largly identical content.
> I've read all the W3C tutorials on XML, XSLT, etc. I'm quite excited
> about the possible uses of XML applied to my current problem and a
> myriad of other applications (such a simple idea, but so bloody
> useful). However my mind is currently a potpourri of half baked ideas.
> I'm failing to get a proper grasp on exactly how to utilise xml.


XML is just one way to describe (tree) structured data. If you are
working with that (you are), it's nice to have a well known and standard
description. XSML it that

> I'm wondering if I could modify the xhtml files to xml and use tags to
> decide what to display?


Well .. files and tags can't decide anything. What you want to do is to
decorate your contets with some more information, which is useful for
the program that will decide what to include. Your member elements are that.

The decision-implementing program could be this stylesheet:

blog.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xslutput method="xml"/>

<xslaram name="loggedin" select="'false'"/>

<!-- rule that renames the blog element to html -->
<xsl:template match="blog">
<html>
<xsl:apply-templates/>
</html>
</xsl:template>

<!-- default rule that copies everything, even attributes -->
<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()"/>
</xsl:copy>
</xsl:template>

<!-- rule that overrides the default rule for member elements-->
<xsl:template match="member">
<!-- if logged in, forget about the member element but recurse to
copy all its children. If not logged in, do not recurse the copying. -->
<xsl:if test="$loggedin='true'">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>

</xsl:stylesheet>


(I have altered your input a little, just adding a blog element around
all of it .. if not everything is contained in a single root element,
it's not valid XML):

blog.xml:
<?xml version="1.0"?>
<blog>
<h1>My Page</h1>
<p><em>16/03/2005</em><br />
Sorry, we were offline for a few hours this morning, someone tripped
over the extension lead.
</p>
<member>
<p>
<strong><em>03/03/2005</em>
<br />
Barton Mawer WINS at the Australian Grand Prix (<a
href="lindsay/bartonmawer.htm" target="main">more</a>).</strong>
</p>
</member>
</blog>


The stylesheet, when run on the input, takes a parameter loggedin. I
have made a couple of test runs, feeding a value for the parameter to
the stylesheet processor:


[dongfang@granada membersonly]$ xsltproc --stringparam loggedin false
blog.xsl blog.xml
<?xml version="1.0"?>
<html>
<h1>My Page</h1>
<p><em>16/03/2005</em><br/>
Sorry, we were offline for a few hours this morning, someone tripped
over the extension lead.
</p>

</html>


and

[dongfang@granada membersonly]$ xsltproc --stringparam loggedin true
blog.xsl blog.xml
<?xml version="1.0"?>
<html>
<h1>My Page</h1>
<p><em>16/03/2005</em><br/>
Sorry, we were offline for a few hours this morning, someone tripped
over the extension lead.
</p>

<p>
<strong><em>03/03/2005</em>
<br/>
Barton Mawer WINS at the Australian Grand Prix (<a
href="lindsay/bartonmawer.htm" target="main">more</a>).</strong>
</p>

</html>

> 1) Am I on the right track? Is XML the answer to my problem?

It's one answer, and seemingly an easy one. Of course you will have to
figure how to make your server fire up a stylesheet processor, send a
parameter to it, and send the output to the client -- but that's a
standard technique. You may even leave the transformation to be done by
the client -- but of course nonmembers will still have the member stuff
served (just not displayed). They could see it if they view the page
source code.

> 2) Is there an easy way of separating the content without having to
> parse all the xhtml tags as well as the xml tags???

Not really. Copying a chunk of data involves finding out where the end
of it is. That involves parsing, if it's a section of text in the middle
of a file. But it doesn't hurt all that much.

> 3) If so, I need to get a better understanding of XML, what is your
> suggested next step after reading the W3C tutorial?

an XLST tutorial?

Good luck
Soren

 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      04-14-2005
(E-Mail Removed) wrote:

> G'day All,
> I hope you folk are tolerant of newbies who don't express themselves
> well, cause I'm one of those. If not please excuse this and move on.


No problem. We all have to start somewhere.

> I'm designing a small web site and while I thought I'd done a good job
> of planning the project and learning the required skills I've now
> discovered a hole in my plan.
>
> I'm using a template like php script to the build pages.
> I'm also using php sessions to authenticate access to members and
> guests.
> The content component is in xhtml.
>
> Now I'm at the testing stage, I've started to prepare a few of the
> xhtml files and realised a lot of the content is an amalgum of 'guest'
> and 'member' stuff. I don't really want to have a separate page for
> each class of user, with largly identical content.


If you've spotted that unaided then you are already way ahead

> I'm wondering if I could modify the xhtml files to xml and use tags to
> decide what to display?


Certainly. (Just a small terminological point: they're elements, not tags,
see http://www.ucc.ie/xml/#makeup)

> i.e. the stuff enclosed by the <member> tag should only be written to a
> member session.
>
> <h1>My Page</h1>
> <p><em>16/03/2005</em><br />
> Sorry, we were offline for a few hours this morning, someone tripped
> over the extension lead.
> </p>
> <member>
> <p>
> <strong><em>03/03/2005</em>
> <br />
> Barton Mawer WINS at the Australian Grand Prix (<a
> href="lindsay/bartonmawer.htm" target="main">more</a>).</strong>
> </p>
> </member>
>
> My questions are:
> 1) Am I on the right track? Is XML the answer to my problem?


Yes, absolutely. I don't know how to do it in PHP, though.

> 2) Is there an easy way of separating the content without having to
> parse all the xhtml tags as well as the xml tags???


No. A parser has to read and digest the whole document from start to finish
(actually that's a lie, there are fragment parsers, but leave them alone
for the moment).

If you were using XSLT, for example, your stylesheet might contain something
like this:

<xsl:choose>
<xsl:when test="$sessiontype='member'">
<xsl:apply-templates select="member"/>
<xsl:when>
<xsl:when test="$sessiontype='guest'">
<xsl:apply-templates select="guest"/>
<xsl:when>
</xsl:choose>

Actually, have a look at attributes. It might be better to say

<h1>My Page</h1>
<p><em>16/03/2005</em><br />
Sorry, we were offline for a few hours this morning, someone tripped
over the extension lead.
</p>
<div class="news:member">
<p>
<strong><em>03/03/2005</em>
<br />
Barton Mawer WINS at the Australian Grand Prix (<a
href="lindsay/bartonmawer.htm" target="main">more</a>).</strong>
</p>
</div>

and teach your PHP/xml to distinguish between news:member and news:guest

> 3) If so, I need to get a better understanding of XML, what is your
> suggested next step after reading the W3C tutorial?


Try the FAQ if you haven't already (www.ucc.ie/xml/) and a good book on
XML for online applications. I can't recommend a specific one, there are
too many, but an hour or so spent browsing them at a large tech bookstore
would be useful.

///Peter
--
sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
&;top"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
a split is not a split Dumbell Computer Support 3 03-09-2009 10:45 PM
How can I split database results with ExecuteReader and Split? needin4mation@gmail.com ASP .Net 2 05-05-2006 10:36 PM
split on '' (and another for split -1) trans. (T. Onoma) Ruby 10 12-28-2004 06:36 AM
Small inconsistency between string.split and "".split Carlos Ribeiro Python 11 09-17-2004 05:57 PM



Advertisments