SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: XML Attributes

  1. #1
    SitePoint Zealot ohnnyj's Avatar
    Join Date
    Jun 2003
    Location
    California
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML Attributes

    Hello all:

    Anyone know how to set an attribute for the root <?xml node in in PHP 5?

    Thanks,

    - John -

  2. #2
    SitePoint Zealot Caged's Avatar
    Join Date
    May 2003
    Location
    United States
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume your talking about the 'decleration', that only defines the version and character encoding, you can't add attributes to it. Its not a node at all. Your root node will be what directly follows that.

  3. #3
    SitePoint Zealot ohnnyj's Avatar
    Join Date
    Jun 2003
    Location
    California
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry. Yes, I am talking abou the XML declaration. So there is no way to tell PHP to include a certain encoding?

    Thanks,

    - John -

  4. #4
    SitePoint Zealot Caged's Avatar
    Join Date
    May 2003
    Location
    United States
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume your talking about the 'decleration', that only defines the version and character encoding, you can't add attributes to it. Its not a node at all. Your root node will be what directly follows that.
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>

  5. #5
    SitePoint Zealot ohnnyj's Avatar
    Join Date
    Jun 2003
    Location
    California
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In code. I know how to write the XML, but when generating the DOM from PHP it creates the declaration on its own w/the bare minimum:

    <?xml version="1.0" ?>

    I need to add it after the fact.

    - John -

  6. #6
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ohnnyj
    In code. I know how to write the XML, but when generating the DOM from PHP it creates the declaration on its own w/the bare minimum:

    <?xml version="1.0" ?>

    I need to add it after the fact.

    - John -
    When you create your DomDocument you can specify the version and the character encoding in the constructor.

    PHP Code:
    $xmldoc = new DomDocument("1.0""iso-8859-1"); 
    JT

  7. #7
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry. Yes, I am talking abou the XML declaration.
    I was pondering on this myself with PHPversion4 a while back, although with the DOCTYPE as well as the XML declaration

    Didn't get very far though

  8. #8
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Widow Maker
    I was pondering on this myself with PHPversion4 a while back, although with the DOCTYPE as well as the XML declaration

    Didn't get very far though
    The same thing can be accomplished in PHP4. There are parameters to pass in to domxml_* functions for version and character encoding when you are creating the document and when you are saving it to file or printing to screen.

    JT

  9. #9
    SitePoint Zealot ohnnyj's Avatar
    Join Date
    Jun 2003
    Location
    California
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome, just what I needed, thanks guys!

    - John -

  10. #10
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seratonin,

    Thought of that, but I couldn't get the DOCTYPE it's self working. Do you have an example ?

  11. #11
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Widow Maker
    Seratonin,

    Thought of that, but I couldn't get the DOCTYPE it's self working. Do you have an example ?
    I think you have to use the doctype function which returns an instance of the DomDocumentType class and then manipulate it that way. I've never tried it and it is poorly documented.

    http://us4.php.net/manual/en/functio...nt-doctype.php

    JT


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
  •