SitePoint Sponsor

User Tag List

Page 4 of 6 FirstFirst 123456 LastLast
Results 76 to 100 of 142
  1. #76
    SitePoint Guru momos's Avatar
    Join Date
    Apr 2004
    Location
    Belgium
    Posts
    919
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by timvw
    But there still aren't b-nodes that hold multiple a-nodes..
    This feels like bad will...

    <a id="fruit">
    <b>apple</b>
    <b>tomato</b>
    </a>
    <a id="vegetables">
    <b>tomato</b>
    </a>

    The b-node tomato has an a-node with id=fruit and one with id=vegetable

  2. #77
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No bad will intended, i just didn't find it that easy human interpretable.

    I admit an a-node can hold multiple b-nodes and b-nodes can have multiple a-nodes in your example. But do you see how you have copied the b-node into each a-node? Right now it may seem not that important, but imagine if each node had also multiple c-nodes. You would have to copy into each a-node that has the b-node too.. It is for that sort of redundancy we throw out the hierarchical model and choose for a relational one.

  3. #78
    SitePoint Guru momos's Avatar
    Join Date
    Apr 2004
    Location
    Belgium
    Posts
    919
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But a data-model with a lot of many-to-many relationshipst is not really a simple model. On the other had, I don't know if you ever wrote some .NET code, their datasets are all XML, and can contain many-to-many relationships.

  4. #79
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by timvw
    No bad will intended, i just didn't find it that easy human interpretable.

    I admit an a-node can hold multiple b-nodes and b-nodes can have multiple a-nodes in your example. But do you see how you have copied the b-node into each a-node? Right now it may seem not that important, but imagine if each node had also multiple c-nodes. You would have to copy into each a-node that has the b-node too.. It is for that sort of redundancy we throw out the hierarchical model and choose for a relational one.
    Haven't you heard of references ?
    Code:
    <a id="vegetables">
    <b>tomato</b>
    </a>
    <a id="fruit" inherits="vegetables">
    <b>apple</b>
    </a>
    and with the following DTD:
    Code:
    <!ELEMENT a (b+)>
    <!ATTLIST a id ID #REQUIRED
                      inherits IDREF #IMPLIED>
    <!ELEMENT b (#PCDATA)>

  5. #80
    SitePoint Zealot Nate's Avatar
    Join Date
    Sep 2001
    Location
    BC, Canada
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The advantage is /generating/ XML for output with PHP!

    Quote Originally Posted by hgilbert
    Often I find it can help reduce complexity
    You extract data (xml) from presentation (xslt)
    The output is then (xhtml).
    This is a concept I've been working with for the past couple months.

    I use PHP to generate all my content (even content out of a DB!), but instead of printing out XHTML with my dynamic content littered throughout it, I generate a XML document of all my dynamic content, then apply an XSL template that incorporates that same static XHTML. It's quite powerful and remarkably elegant, if I may say so myself.

    I've created a class that will take an array (created with basically the same hierarchy that I want my XML to have) and, at its most simple form, turn it into <key>value</key>. Obviously it is significantly more capable than that, but that's the basic idea.

    I'd be happy to give a better demonstration/explanation of how I've implemented this, even release my class, if there is sufficient interest. I'd like to be able to show it somewhere off the forums, but I don't have a suitable host... so if anyone can help there (either by hosting or knowing of somewhere good/free) please send me a PM
    NATHAN WRIGHT
    PHP Developer, Simple Station

  6. #81
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by momos
    On the other had, I don't know if you ever wrote some .NET code, their datasets are all XML, and can contain many-to-many relationships.
    As i already posted, i figured out a solution that allowed me to model a n-m relationship in XML, the same way as it's done in a SQL table. (By introducing a reference node/table that contains the primary keys of the nodes. Notice that the redundancy has been reduced, however it's not completely gone (copying the primary key))

    A disadvantage of the XML that (afaik) it's impossible with DTD/XSD to describe the allowed values for the a- and b- attributes in the ab nodes.

    Code:
    <a-nodes>
    <a id='a1'/>
    <a id='a2'/>
    </a-nodes>
    <b-nodes>
    <b id='b1'/>
    </b-nodes>
    <ab-nodes>
    <ab a='a1' b='b2'/>
    </ab-nodes>

  7. #82
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by timvw
    A disadvantage of the XML that (afaik) it's impossible with DTD/XSD to describe the allowed values for the a- and b- attributes in the ab nodes.

    Code:
    <a-nodes>
    <a id='a1'/>
    <a id='a2'/>
    </a-nodes>
    <b-nodes>
    <b id='b1'/>
    </b-nodes>
    <ab-nodes>
    <ab a='a1' b='b2'/>
    </ab-nodes>
    You've got to be kidding, right ?
    Look above at my example (if you haven't noticed it) and please note that attribute inherits is of type IDREF and every parser will issue an error if the id doesn't exist.

  8. #83
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Nate
    I use PHP to generate all my content (even content out of a DB!), but instead of printing out XHTML with my dynamic content littered throughout it, I generate a XML document of all my dynamic content, then apply an XSL template that incorporates that same static XHTML. It's quite powerful and remarkably elegant, if I may say so myself.
    I like that approach too. (Although sometimes, i prefer to use one of the many available php classes that generate html)

    Quote Originally Posted by Nate
    I've created a class that will take an array (created with basically the same hierarchy that I want my XML to have) and, at its most simple form, turn it into <key>value</key>. Obviously it is significantly more capable than that, but that's the basic idea.
    Here is a MySQL2XML snippet

    PHP Code:
            while($row mysql_fetch_assoc($result))
            {
                
    $occ $doc->createElement('entity');
                
    $occ $root->appendChild($occ);

                foreach(
    $row as $fieldname => $fieldvalue)
                {
                    
    $child $doc->createElement('attribute');
                    
    $child->setAttribute('name'$fieldname);
                    
    $child $occ->appendChild($child);
                    
    $fieldvalue mb_convert_encoding($fieldvalue,'UTF-8''ISO-8859-1');
                    
    $value $doc->createTextNode($fieldvalue);
                    
    $value $child->appendChild($value);
                }
            } 

  9. #84
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @timvw
    Am I invisible or something ?

  10. #85
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bonefry
    @timvw
    Am I invisible or something ?
    No, i'm not ignoring you

    I'm learning.. I'm reading Chapter3 (IDREF etc ) in the XML specification..

  11. #86
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by timvw
    No, i'm not ignoring you

    I'm learning.. I'm reading Chapter3 (IDREF etc ) in the XML specification..

    Try this: http://www.w3schools.com/dtd/default.asp
    It's easier to read.

  12. #87
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bonefry
    Haven't you heard of references ?
    Code:
    <a id="vegetables">
    <b>tomato</b>
    </a>
    <a id="fruit" inherits="vegetables">
    <b>apple</b>
    </a>

    Well, i've searched http://www.w3.org/TR/2004/REC-xml-20040204 and the only "references" i found where entity and character references. So, i think i haven't heard about references. Where can i hear about them?

    Currently, you seem to use a "reference" (somewhat a foreign key) in the a-fruit node to the a-vegetables node. That is exactly the same i did with the a,b, ab-nodes example. So i don't know why you asked that i was kidding there?

    Below is an example of XML and DTD i would like to use. I want to apply a constraint on the values of the aid and bid attributes of the ab nodes. The point is to allow only IDs from an a-node as aid value, and IDs from a b-node as bid value.

    IDREF only checks if there is some node with that ID.
    IDREFS doesn't seem usable, because i don't know beforehand which IDs my a-nodes and/or b-nodes will have.

    Code:
    <?xml version="1.0"?>
    <!DOCTYPE root [
     <!ELEMENT root (a-nodes, b-nodes, ab-nodes)*>
     <!ELEMENT a-nodes (a*)>
     <!ELEMENT b-nodes (b*)>
     <!ELEMENT ab-nodes (ab*)>
     <!ELEMENT a (#PCDATA)>
     <!ELEMENT b (#PCDATA)>
     <!ELEMENT ab (#PCDATA)>
     <!ATTLIST a id ID #REQUIRED>
     <!ATTLIST b id ID #REQUIRED>
     <!ATTLIST ab aid IDREF #REQUIRED
    	             bid IDREF #REQUIRED> 
    ]>
    <root>
    <a-nodes>
     <a id='a1'>hihii</a>
    </a-nodes>
    <b-nodes>
     <b id='b1'/>
     <b id='b2'/>
    </b-nodes>
    <ab-nodes>
     <ab aid='a1' bid='a1'/>
    </ab-nodes>
    </root>
    Feel free to provide a DTD that allows me to specify this

    Btw, as XSD was also allowed as scheme, i think it's possible to declare the constraint with <xs:restriction>.

  13. #88
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by timvw
    Feel free to provide a DTD that allows me to specify this
    Dude, you want too much validation. These kind of validation it's better off done directly in PHP or XSLT.

    EDITED: the DTD or XSD validation are usefull only to validate syntax, and not logical mistakes

  14. #89
    SitePoint Zealot Nate's Avatar
    Join Date
    Sep 2001
    Location
    BC, Canada
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by timvw
    Here is a MySQL2XML snippet

    PHP Code:
             while($row mysql_fetch_assoc($result))
             {
                 
    $occ $doc->createElement('entity');
                 
    $occ $root->appendChild($occ);
     
                 foreach(
    $row as $fieldname => $fieldvalue)
                 {
                     
    $child $doc->createElement('attribute');
                     
    $child->setAttribute('name'$fieldname);
                     
    $child $occ->appendChild($child);
                     
    $fieldvalue mb_convert_encoding($fieldvalue,'UTF-8''ISO-8859-1');
                     
    $value $doc->createTextNode($fieldvalue);
                     
    $value $child->appendChild($value);
                 }
             } 
    This is significantly more complicated than it needs to be.

    Heres what mine looks like.
    PHP Code:
    $out = array();
     
    $out['entry'] = array();
     while(
    $entry $db->fetch_array($entry_temp))
     {
         
    $out['entry'][] = array(
             
    'id' => $entry['id'],
             
    'topic' => $entry['topic'],
             
    'date' => date('D j M Y'$entry['datetime']),
             
    'time' => date('H:i'$entry['datetime']),
             
    'comments' => $entry['comments'] . ' Comments',
             
    'body' => $entry['body']
         );
     } 
    That generates XML of identical form. The class that I'm using can also handle attributes and multiple repetitions of the same tag (shown in the way that new elements of $out['entry'] are created).
    HTML Code:
    <entry>
     	<id>6</id>
     	<topic>The First Entry</topic>
     	<date>Tue 2 Aug 2005</date>
     	<time>15:50</time>
     	<comments>4 Comments</comments>
     	<body>This is an example entry.</body>
     </entry>
     <entry>
     	<id>7</id>
     	<topic>The First Entry</topic>
     	<date>Tue 3 Aug 2005</date>
     	<time>18:27</time>
     	<comments>0 Comments</comments>
     	<body>This is another example entry.</body>
     </entry>
    You tell me which is cleaner
    NATHAN WRIGHT
    PHP Developer, Simple Station

  15. #90
    SitePoint Enthusiast Codebox's Avatar
    Join Date
    Jan 2004
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    rikshot, u r very right in that you dont really need to use XML for what you are doing... the advantage of xml is:

    your separate your content "completely"!.. e.g. here is an xml file that holds content for ur company:

    <company>
    <name>2Cool Web Design</name>
    <phone>123-456-789</phone>
    </company>

    now you can use this single data source in several applications at the same time.... e.g. a flash site thats shows ur phone number... an html site showing ur phonu number ... then goes your WAP site.. so the basic purpose is to create a single easy to edit data file that will be useful in the future where several different devices will be using the net and visiting your site...

    the content will be there.. the mediums of delivery change..

    currently (in XHTML), you do not have too much customization to allow your content to work everywhere...

    But say, if you are to accept orders via phone... and use VocieXML... then again.. XML rocks!..

    i hope my long speech was somewhat useful

    regards,
    Kamran.

  16. #91
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    XML is about exchanging data and presenting it in a neutral format that can be understood by many devices and applications. Sure, it's also good for storing small amounts of data records, but not for many many records, that's why we have relational databases. Think of XML as at the middleware that sits between a proprietary system and newer systems, or as a translator between yourself and a non English speaker. It's about data interchange, rather than data storage.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  17. #92
    SitePoint Guru momos's Avatar
    Join Date
    Apr 2004
    Location
    Belgium
    Posts
    919
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The future will show us what XML is meant for... at the moment it is one of those buzzwords, which makes people think it is good for everything...

  18. #93
    SitePoint Guru dagfinn's Avatar
    Join Date
    Jan 2004
    Location
    Oslo, Norway
    Posts
    894
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by R. U. Serious
    I had to laugh really hard, when i read that. Beause it alrady was the next big thing several years ago, only the promises that were made were (IMHO) never really fulfilled. But it looks a lot better today than a few years ago, it might actually be possible that we get there someday...
    I was watching "Judging Amy" on TV yesterday, and Amy said:
    If I don't stop [eating this], my butt will be the next big thing.
    That's about as profound as any other statement about the "next big thing".
    Dagfinn Reiersøl
    PHP in Action / Blog / Twitter
    "Making the impossible possible, the possible easy,
    and the easy elegant"
    -- Moshe Feldenkrais

  19. #94
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You tell me which is cleaner
    Well, how would you do the following, when you have another level to deal with, as such as this for example, via your array implementation?

    Code:
    ...
    <author>
    <firstname> ... </firstname>
    <lastname> ... </lastname>
    ...</author>
    I would think that generating the tags on the fly is the better approach, more cleaner and easier to implement? An alternative, would be to build up the XML as a string instead, then create a DOM object using that string

  20. #95
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,638
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Well, how would you do the following, when you have another level to deal with, as such as this for example, via your array implementation?

    Code:
    ...
    <author>
    <firstname> ... </firstname>
    <lastname> ... </lastname>
    ...</author>
    I would think that generating the tags on the fly is the better approach, more cleaner and easier to implement? An alternative, would be to build up the XML as a string instead, then create a DOM object using that string
    I would really avoid this. If you are making an XML object, use the DOM. Creating XML from strings leads to issues like character encoding and such.

    Unless you write your own encoding algorithm. Which would be a bit of a waste, as well as be much slower than just using the DOM in the first place.

  21. #96
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wwb_99
    I would really avoid this. If you are making an XML object, use the DOM. Creating XML from strings leads to issues like character encoding and such.

    Unless you write your own encoding algorithm. Which would be a bit of a waste, as well as be much slower than just using the DOM in the first place.
    What makes you think the DOM implementation in PHP doesn't have bugs ? In fact the first versions of the new libxml2 based parser, when I last tried to work with unicode, it froze when trying. And I documented myself and found it was a well known bug. It's stupid to generate XML with DOM simply because it is more time consuming and error-prone (yes, due to bugs, they always have bugs in PHP).

    Also, when creating XML with DOM, aren't you using strings anyways ? (for the values and field names and all that). What changes ?

  22. #97
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,638
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    XML is not a big string that happens to be valid XML. Xml is an in memory object expressed through the dom that happens to be easily serialzable into a string representation. It is made up of trees, nodes and leafs not character data.

    PHP DOM implementation issues aside, there are significant issues with generating Xml through string concatenation.

    1) The biggest one is character escapes and encoding. Now, this can be mitigated somewhat by using CDATA nodes. But that is an ugly kludge at best. What it leads to is that one need write a perfect string scrubbing function. Which is difficult to get perfect and grossly inefficent in anything short of C.
    2) The onust of maintaining valid Xml structures falls onto the application, not the Xml library. For simple stuff, like most of the above examples, it is not too tricky. But get something complex and real-world and you can have alot of trouble with this.
    3) Given that the DOM implementation, even if it has some bugs, is written in compiled machine code rather than interperted PHP, it can handle one and two alot better than your script can. Furthermore, since all it is concerned with doing is handling Xml in a proper and valid manner, I would bet on it having less bugs than a custom Xml implementation.

    Bottom line: Xml is not a string. Don't treat it like one.

  23. #98
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was looking at the php internals list, and it looks like they are going to vote on including the XMLWriter extension in the main php dist.
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  24. #99
    throw me a bone ... now bonefry's Avatar
    Join Date
    Nov 2004
    Location
    Romania
    Posts
    848
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wwb_99
    XML is not a big string that happens to be valid XML. Xml is an in memory object expressed through the dom that happens to be easily serialzable into a string representation. It is made up of trees, nodes and leafs not character data.
    You are mistaking XML for DOM. There are other ways to parse it you know, like SAX. And it's an object only if you look at it like that. Because you can also look at it as a relational table for example.

    Quote Originally Posted by wwb_99
    The biggest one is character escapes and encoding.
    The only encodings necessary are < that becomes a &lt; and & that becomes an &amp;

    Quote Originally Posted by wwb_99
    Given that the DOM implementation, even if it has some bugs, is written in compiled machine code rather than interperted PHP, it can handle one and two alot better than your script can.
    You give compiled code too much credit. What can be more faster than a simple echo ?

  25. #100
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,638
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    You are mistaking XML for DOM. There are other ways to parse it you know, like SAX. And it's an object only if you look at it like that. Because you can also look at it as a relational table for example.
    We are talking about writing Xml, not reading Xml here. SAX is great for reading. In fact, most DOM implementations use a SAX reader to build the DOM tree.

    The only encodings necessary are < that becomes a &lt; and & that becomes an &amp;
    IIRC, alot more encodings are necessary. Like &quot;. Then you get into funky characters that don't really belong but appear. Like crap from Word.

    You give compiled code too much credit. What can be more faster than a simple echo ?
    A compiled echo:
    Code:
    #include <stdio.h>
    int main(void)
    {
      printf("Hello World!\n");
      exit(0);
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •