Just in case it isn't clear (like I had), an example:
<?php
$domDocument = new DOMDocument('1.0', "UTF-8");
$domElement = $domDocument->createElement('field','some random data');
$domAttribute = $domDocument->createAttribute('name');
// Value for the created attribute
$domAttribute->value = 'attributevalue';
// Don't forget to append it to the element
$domElement->appendChild($domAttribute);
// Append it to the document itself
$domDocument->appendChild($domElement);
?>
Will output:
<?xml version="1.0" encoding="UTF-8"?>
<field name="attributevalue">some random data</field>
DOMDocument::createAttribute
(PHP 5)
DOMDocument::createAttribute — Yeni bir öznitelik düğümü oluşturur
Açıklama
Yeni bir DOMAttr nesnesi oluşturur. Bu düğüm, DomNode::append_child() gibi bir yöntemle belgeye yerleştirilmedikçe belgede gösterilmez.
Değiştirgeler
-
isim -
Özniteliğin ismi.
Dönen Değerler
Bir hata oluşursa FALSE yoksa yeni
bir DOMAttr nesnesi döner.
Hatalar/İstisnalar
-
DOM_INVALID_CHARACTER_ERR -
isimgeçersiz karakter içeriyorsa oluşur.
Ayrıca Bakınız
- DOMNode::appendChild() - Listenin sonuna yeni bir çocuk ekler
- DOMDocument::createAttributeNS() - Yeni bir isim alanlı öznitelik düğümü oluşturur
- DOMDocument::createCDATASection() - Yeni bir CDATA düğümü oluşturur
- DOMDocument::createComment() - Yeni bir açıklama düğümü oluşturur
- DOMDocument::createDocumentFragment() - Yeni bir belge bölütü oluşturur
- DOMDocument::createElement() - Yeni bir eleman düğümü oluşturur
- DOMDocument::createElementNS() - İsim alanlı bir eleman düğümü oluşturur
- DOMDocument::createEntityReference() - Yeni bir öğe bildirimi düğümü oluşturur
- DOMDocument::createProcessingInstruction() - Yeni bir işlem komutu düğümü oluşturur
- DOMDocument::createTextNode() - Yeni bir metin düğümü oluşturur
Beerkeeper
09-Nov-2011 12:19
