PHP.mk документација

DOMDocument::createAttributeNS

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

domdocument.createattributens.php PHP.net прокси Преводот е вчитан
Оригинал на PHP.net
Патека domdocument.createattributens.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + преведен приказ Кодовите, табелите и белешките остануваат читливи во истиот тек.
DOMDocument::createAttributeNS

Референца за `domdocument.createattributens.php` со подобрена типографија и навигација.

domdocument.createattributens.php

DOMDocument::createAttributeNS

класата mysqli_driver

DOMDocument::createAttributeNS Креирај нов јазол за атрибут со поврзан именски простор

= NULL

public DOMDocument::createAttributeNS(?string $namespace, string $qualifiedName): DOMAttr|false

Create new text node DOMAttrThis function creates a new instance of class . This node will not show up in the document unless it is inserted with (e.g.).

Параметри

namespace

URI на именскиот простор.

qualifiedName

Името на ознаката и префиксот на атрибутот, како prefix:tagname.

Вратени вредности

Новиот DOMAttr or false аргумент, или

Errors/Exceptions

Може да фрли DOMException со следните кодови за грешки:

DOM_INVALID_CHARACTER_ERR

Покренато ако qualifiedName содржи невалиден знак.

DOM_NAMESPACE_ERR

Покренато ако qualifiedName е погрешно формирано квалификувано име, или ако qualifiedName има префикс и namespace is null.

Дневник на промени

Верзија = NULL
8.3.0 Оваа функција сега има привремен тип на враќање true.
8.3.0 Повикувањето на овој метод со префикс што веќе беше деклариран на сопственичкиот елемент со различен URI за именски простор сега ќе го промени новиот префикс за да се избегнат конфликти на именски простор. Ова го усогласува однесувањето со спецификацијата DOM. Претходно ова фрлаше DOMException со код DOM_NAMESPACE_ERR.

Види Исто така

Белешки од корисници 1 белешка

BadGuy [at] BadGuy [dot] nl
пред 15 години
If a new namespace is introduced while creating and inserting an attribute, createAttributeNS() does not behave in the same way as createElementNS().

(1) Location: With createAttributeNS(), the new namespace is declared at the level of the document element. By contrast, createElementNS() declares the new namespace at the level of the affected element itself.

(2) Timing: With createAttributeNS(), the new namespace is declared in the document as soon as the attribute is created - the attribute does not actually have to be inserted. createElementNS() doesn't affect the document as long as the element is not inserted.

An example:

<?php
    
    $source = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<root><tag></tag></root>
XML;
    
    /*
     
     I. createAttributeNS:
     * a new namespace shows up immediately, even without insertion of the attribute
     * the new namespace is declared at the level of the document element
     
    */
    
    $doc = new DOMDocument( '1.0' );
    $doc->loadXML( $source );
    
    // (1) We just create a "namespace'd" attribute without appending it to any element.
    $attr_ns = $doc->createAttributeNS( '{namespace_uri_here}', 'example:attr' );
    
    print $doc->saveXML() . "\n";
    
    /*
      Result: The namespace declaration appears, having been added to the document element. Output:
      
      <?xml version="1.0" encoding="UTF-8"?>
      <root xmlns:example="{namespace_uri_here}"><tag/></root>
      
    */
    
    // (2) Next, we give the attribute a value and insert it.
    $attr_ns->value = 'value'; 
    $doc->getElementsByTagName( 'tag' )->item(0)->appendChild( $attr_ns );
    
    print $doc->saveXML() . "\n";
    
    /*
      Result: The "namespace'd" attribute shows up as well. Output:
      
      <?xml version="1.0" encoding="UTF-8"?>
      <root xmlns:example="{namespace_uri_here}"><tag example:attr="value"/></root>
      
    */
    
    /*
     
     II. createElementNS:
     * a new namespace shows up only when the element is inserted
     * the new namespace is declared at the level of the inserted element
     
    */
    
    $doc = new DOMDocument( '1.0' );
    $doc->loadXML( $source );
    
    // (1) We create a "namespace'd" element without inserting it into the document.
    $elem_ns = $doc->createElementNS( '{namespace_uri_here}', 'example:newtag' );
    
    print $doc->saveXML() . "\n";
    
    /*
      Result: The document remains unchanged. Output:
      
      <?xml version="1.0" encoding="UTF-8"?>
      <root><tag/></root>
      
    */
    
    // (2) Next, we insert the new element.
    $doc->getElementsByTagName( 'tag' )->item(0)->appendChild( $elem_ns );
    
    print $doc->saveXML() . "\n";
    
    /*
      Result: The namespace declaration appears, and it is embedded in the element using it. Output:
      
      <?xml version="1.0" encoding="UTF-8"?>
      <root><tag><example:newtag xmlns:example="{namespace_uri_here}"/></tag></root>
      
    */
    
?>
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.