SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)

    DOMDocument XHTML and PHP

    Hey guys. There's a sub-part to one of my applications that needs to manipulate a custom xhtml element, much like aspx or prado. Unfortunately, my xml skills reek. I know the super-duper-basics, but that's it.

    Right now, the template being read in using DOMDocument->load($filename). The template is well formed xhtml with a xml version line instead of a DOCTYPE type (I replace this during output.

    What the routine is supposed to do, is to look for a custom element which has part-templates of it's own, much like the sample below:

    <ssc:table ...attrs...>
    <ssc:table-row-template>
    ...some html to repeat...
    </ssc:table-row-template>
    </ssc:table>

    Look familiar right? Well here's the thing. I can't figure out how to make the ssc prefix valid, correctly. I added the following to the html tag def:


    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ssc=http://ragingpenguin.com/ssc>

    There's no such folder on my domain. I don't really understand what it's for anyway. Funny thing is, it no longer complains about the prefix. Now the problem becomes, how do I grab the element? getElementByID and getElementsByTagName no longer find it.

    Can anybody provide an idiot proof explanation and example of how to get it working?

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Namespace URI should be in quotes:
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ssc="http://ragingpenguin.com/ssc">
    It should not be real URL, actually any URI is acceptable, you only need to use the same URI for the same tags.

    You can use getElementsByTagNameNS (http://www.php.net/manual/en/domdocu...ytagnamens.php) function to select nodes with namespace.
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I left the quotes off, in the post, accidentally. They are present in the real file.

    On a more basic note, how is the system using the URI? Is it expecting something there, like a definition or anything? That's one thing I don't understand. If it isn't really getting used, why have it?

  4. #4
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Namespaces are close to schemas. It is a replacement for DTD - in past you may have only one DTD per document and if you need to define additional tags, you need to include them in DTD. But with schemas you can mix tags from different schemas in one document. If your document does not require validation (no defined structure) then you can avoid them. But if you, for example, creating document that will be used by some system (XSL processor, for example) your document should contain only tags this system understands. E.g. the structure of the tags should be valid against schema.

    Examples:

    1. XHTML has own namespace and schema which defines the allowed tags and attributes.
    2. XSL transformation has own namespace and shema.

    You can mix XSL and XHTML tags in one document so the XSLT processor understands its tags and do not touch XHTML tags.
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  5. #5
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    So I would put an xsd file there? How would I name it? index.xsd? So when an external system used it (domain.com/namespace) it would pull it up?

  6. #6
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    XSD file is used only during XML document validation, e.g. a special process that document data conforms schema (http://msdn.microsoft.com/en-us/libr...23(VS.85).aspx).
    Here is example on how XML document is validated: http://msdn.microsoft.com/en-us/library/wc8csdkz.aspx

    PHP example:
    Code:
    <?php
    $doc = new DOMDocument();
    $doc->load('library.xml');
    $doc->schemaValidate('library.xsd');
    echo "<hr/>";
    library.xml
    Code:
    <?xml version="1.0"?> 
    <library>
      <book>
       <title>Harry Potter and the Philosopher's Stone</title> 
       <author>J.K. Rowling</author> 
      </book> 
    </library>
    library.xsd
    Code:
    <?xml version="1.0" ?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="library">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="book" minOccurs="1" maxOccurs="unbounded" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?


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
  •