formatting text in an xml datastore

Discussion in 'XML' started by Irvin, Dec 6, 2004.

  1. Irvin

    Irvin Guest

    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>
    Irvin, Dec 6, 2004
    #1
    1. Advertising

  2. Irvin

    Peter Flynn Guest

    Irvin wrote:

    > 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
    --
    "The cat in the box is both a wave and a particle"
    -- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
    Peter Flynn, Dec 6, 2004
    #2
    1. Advertising

  3. Irvin

    Irvin Guest

    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.
    Irvin, Dec 7, 2004
    #3
  4. Irvin

    Joris Gillis Guest

    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,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Dec 7, 2004
    #4
  5. Irvin

    Irvin Guest

    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.
    Irvin, Dec 7, 2004
    #5
  6. Irvin

    Joris Gillis Guest

    >> 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.

    >> 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.
    >

    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>
    </desc>

    >> 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.
    >
    >> Ceterum censeo XML omnibus esse utendum

    > Translated, this means?

    :) Furthermore, I am of the opinion that XML must be used by everyone/for everything.

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Dec 7, 2004
    #6
  7. Irvin

    Irvin Guest

    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.
    Irvin, Dec 7, 2004
    #7
  8. Irvin

    Peter Flynn Guest

    Irvin wrote:

    > 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
    --
    "The cat in the box is both a wave and a particle"
    -- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
    Peter Flynn, Dec 7, 2004
    #8
  9. Irvin

    Peter Flynn Guest

    Irvin wrote:

    > 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
    --
    "The cat in the box is both a wave and a particle"
    -- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
    Peter Flynn, Dec 8, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruno
    Replies:
    0
    Views:
    396
    Bruno
    Jan 3, 2006
  2. Bruno
    Replies:
    4
    Views:
    1,852
    Bruno
    Jan 4, 2006
  3. Irvin
    Replies:
    0
    Views:
    337
    Irvin
    Dec 6, 2004
  4. v4vijayakumar

    More Datastore Examples Please

    v4vijayakumar, Aug 5, 2008, in forum: Python
    Replies:
    3
    Views:
    243
    Tim Roberts
    Aug 9, 2008
  5. RiverWay
    Replies:
    1
    Views:
    1,060
    RiverWay
    Apr 21, 2010
Loading...

Share This Page