formatting text in an xml datastore

I

Irvin

I am using an xml file to store data. I can get the data out now, but I
have a problem with any field that needs text formatting such as bold,
carriage return/linefeed, htmls tags.

Can some one point me to a good tutorial that will help me learn this,
or give me an example?

Thanks,
Irvin.

<product>
<title>My product Title</title>
<prod_date>20.May.1999</prod_date>
<desc>
Paragraph one.
Paragraph two.
</desc>
</product>
 
P

Peter Flynn

Irvin said:
I am using an xml file to store data. I can get the data out now, but I
have a problem with any field that needs text formatting such as bold,
carriage return/linefeed, htmls tags.

Can some one point me to a good tutorial that will help me learn this,
or give me an example?

Use XSLT.
<product>
<title>My product Title</title>
<prod_date>20.May.1999</prod_date>
<desc>
Paragraph one.

This is going to be a problem. You really need to have something better
than a newline in there to signal paragraphs.
Paragraph two.
</desc>
</product>

<desc>
<para>Paragraph one.</para>
<para>Paragraph two.</para>
</desc>

Don't be tempted to pretend that linebreaks are a substitute for paragraph
start and end. They're not.

e.g.:

<xsl:template match="title">
<h1>
<xsl:apply-templates/>
</h1>
</xsl:template>

<xsl:template match="prod_date">
<h2>
<!-- get rid of the periods in the date -->
<xsl:value-of select="translate(.,'.',' ')"/>
</h2>
</xsl:template>

[and much more].

///Peter
 
I

Irvin

Peter,
Thanks for your quick reply. I am completly new to xml! But it looks
like it could be fun to work with.

Anyways, I actually found a way to do what I wanted!
<desc><![CDATA[<p"Paragraph one".</p><p>It's paragraph two.</p>]]
</desc>

But now I have a new problem!

Only part of the text shows up! Is there a limit to the number of
characters that a Node(?) can return? It cuts off mid sentence, no
special charaters nearby. You can take a look here:
http://www.ivan-isabel.com/test/test.xml <- XML datastore
http://www.ivan-isabel.com/test/articles.php <- PHP/XML version (cut
off text)
http://www.ivan-isabel.com/articles.html <- Static version (full text)
Thanks again for your help.

Irvin.
 
J

Joris Gillis

Hi,
Thanks for your quick reply. I am completly new to xml! But it looks
like it could be fun to work with.

Anyways, I actually found a way to do what I wanted!
<desc><![CDATA[<p"Paragraph one".</p><p>It's paragraph two.</p>]]
</desc>

But now I have a new problem!

Only part of the text shows up! Is there a limit to the number of
characters that a Node(?) can return? No, there are no limitations.
It cuts off mid sentence, no
special charaters nearby. You can take a look here:
http://www.ivan-isabel.com/test/test.xml <- XML datastore
http://www.ivan-isabel.com/test/articles.php <- PHP/XML version (cut
off text)
http://www.ivan-isabel.com/articles.html <- Static version (full text)

I don't see any mid-sentence cuts on those pages (maybe you repaired it already), but when I look at the source code of the PHP version, I see this:

<para><p><![CDATA[...is a key to entering into the Father’s kingdom, and
since we know that He wants us to enter in, we are all capable
of opening the door to it.</p></para>
<para><![CDATA[<p class="style">What is prophecy? It is simply hearing the
Father speaking and repeating what He says, perceiving the
Father’s heart for someone and then sharing it with ...

First of all, it's useless to put markup data in a CDATA section. In the genrated HTML as well as in the source XML.
Secondly, the CDATA sections, if used, must be closed with ']]>'
Finally, the 'para' element isn't defined in HTML4.0
Maybe these errors are causing the mid-sentece cuts on your browser.

btw, you could consider to use XHTML, CSS and table-free design:)

regards,
 
I

Irvin

Joris,
Thanks for your reply. I have added comments to your posting.
I don't see any mid-sentence cuts on those pages (maybe you repaired
it already ...

No. I still have that issue. I have tried in IE 6.0 and Mozilla
FireFox.
First of all, it's useless to put markup data in a CDATA section. In
the genrated HTML as well as in the source XML.

Is there a better way to do it? The user needs to be able to add style
his text with bold, italic, and stylesheet classes.
Secondly, the CDATA sections, if used, must be closed with ']]>'

Ya. I caught that after I posted.
Finally, the 'para' element isn't defined in HTML4.0

I already dropped that.
btw, you could consider to use XHTML, CSS and table-free design:)

I have never looked at XHTML before.
Ceterum censeo XML omnibus esse utendum
Translated, this means?

Thnaks again!
Irvin.
 
J

Joris Gillis

I don't see any mid-sentence cuts on those pages (maybe you repaired
it already ...

No. I still have that issue. I have tried in IE 6.0 and Mozilla
FireFox.
That's weird: in my Opera browser, I cannot see any problem, but when I set my preferences to 'indentify as MSIE 6.0' , the line is indeed broken. It seems the algorithm in the PHP that checks the browser type is broken. I cannot help you with that; I don't know any PHP.
the genrated HTML as well as in the source XML.

Is there a better way to do it? The user needs to be able to add style
his text with bold, italic, and stylesheet classes.
Well, CDATA sections are, as the word says, meant to be encapsulate Character Data i.d. characters _without_ markup. So it doesn't make sense to put 'tags' in CDATA, because they will be parsed as &lt; and &gt; .I'd just omit the CDATA declaration (certainly in the HTML generated):
<desc><p"Paragraph one".</p><p>It's paragraph two.</p>
Secondly, the CDATA sections, if used, must be closed with ']]>'

Ya. I caught that after I posted.
Finally, the 'para' element isn't defined in HTML4.0

I already dropped that.
btw, you could consider to use XHTML, CSS and table-free design:)

I have never looked at XHTML before.
roughly spoken, XHTML is HTML written with XML strictness. So you can perform XSLT on a XHTML page, it's more versatile.
Translated, this means?
:) Furthermore, I am of the opinion that XML must be used by everyone/for everything.

regards,
 
I

Irvin

Thanks for your help on this.
With regards to CDATA, the <p> tags seem to be presented well in the
browser. It doesn't appear to break anything. If I take them out I
loose my paragraph style and end up with one long paragraph.


I will post this whole issue with a PHP/XML forum and see what they
say.

Irvin.
 
P

Peter Flynn

Irvin said:
Peter,
Thanks for your quick reply. I am completly new to xml! But it looks
like it could be fun to work with.

Anyways, I actually found a way to do what I wanted!
<desc><![CDATA[<p"Paragraph one".</p><p>It's paragraph two.</p>]]
</desc>

Yes, but don't be misled. The text inside a CDATA Marked Section is
*not* XML or HTML, as far as the processor is concerned, it's just a
bunch of letters and signs with no meaning, so it cannot be accessed
or manipulated as XML or HTML, only output as a string, which by luck
means something in the target environment.

It may not be important in a small test like this, but it's a Really
Bad Way to do things in a live production environment.

(Plus you're missing a closing > in your example)
But now I have a new problem!

Only part of the text shows up! Is there a limit to the number of
characters that a Node(?) can return?
No.

It cuts off mid sentence, no
special charaters nearby. You can take a look here:
http://www.ivan-isabel.com/test/test.xml <- XML datastore
http://www.ivan-isabel.com/test/articles.php <- PHP/XML version (cut
off text)
http://www.ivan-isabel.com/articles.html <- Static version (full text)

I don't use PHP, so this is not clear to me.

///Peter
 
P

Peter Flynn

Irvin said:
Thanks for your help on this.
With regards to CDATA, the <p> tags seem to be presented well in the
browser. It doesn't appear to break anything. If I take them out I
loose my paragraph style and end up with one long paragraph.

That's because you have insufficient markup.

If your users want to make the output look pretty (bold, italics, etc
for only decoration) then forget XML, tell them to use Dreamweaver.

If your users want to use bold, italics, etc to highlight something
important (names, places, quotations, references, etc) then use some
markup which describes that reason, and use XSLT to translate it to
HTML with CSS for display. This will last much longer, because later
on you'll be able to use the same markup to guide transformation to
other formats for other purposes without having to change it.
I will post this whole issue with a PHP/XML forum and see what they
say.

I shudder to think :)

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top