PHP DOMDocument createAttribute () function

👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!

Syntax:
DOMAttr DOMDocument::createAttribute (string $name)
Parameters:This function takes one parameter $name,which contains the name of the attribute.Return Value:This function returns a new one a DOMAttr object on success, or FALSE on error.The following programs illustrate the DOMDocument::createAttribute() function in PHP:Program 1:
// Create a new DOMDocument $domDocument = new DOMDocument ( ’1.0’ , ’iso-8859-1’ );
// Use the createElement() function to create an element node $domElement = $domDocument -> createElement ( ’organization’ , ’A computer science portal’ );
// Use the createAttribute() function to create an attribute node $domAttribute = $domDocument -> createAttribute ( ’name’ );
// Value of the created attribute $domAttribute -> value = ’GeeksforGeeks’ ;
// Add an element to the document $domElement -> appendChild ( $domAttribute );
// Add it to the document itself $domDocument -> appendChild ( $domElement );
// Save the document as XML and display it echo $domDocument -> saveXML();
?>
Exit:
 < organization name = "GeeksforGeeks" > A computer science portal < / organization >
Program 2:
// Create a new DOMDocument $domDocument = new DOMDocument ( ’ 1.0’ , ’iso-8859-1’ );
// Use the createElement() function to create an element node $domElement = $domDocument -> createElement ( ’organization’ , ’GeeksforGeeks’ ); $domAttribute1 = $domDocument -> createAttribute ( ’ name’ );
// Value for the created attribute $domAttribute1 -> value = ’GeeksforGeeks’ ;
// Add an element to the document $domElement -> appendChild ( $domAttribute1 );
// Use the createAttribute() function to create an attribute node $domAttribute2 = $domDocument -> createAttribute ( ’address’ );
// Value for the created attribute $domAttribute2 -> value = ’Noida’ ;
// Add element to document $domElement -> appendChild ( $domAttribute2 );
// Use the createAttribute() function to create an attribute node $domAttribute3 = $domDocument -> createAttribute ( ’email’ );
// Value for the created attribute $domAttribute3 -> value = ’abc @ engineerforengineer.org’ ;
// Add element to document $domElement -> appendChild ( $domAttribute3 );
// Add it to the document itself $domDocument -> appendChild ( $domElement );
// Save the document as XML and display it echo $domDocument -> saveXML();
?>
Exit:
 < organization name = "GeeksforGeeks" address = "Noida" email = "[email protected]" > GeeksforGeeks < / organization >
Link: https://www.php.net/ manual / en / domdocument.createattribute.php

👻 Read also: what is the best laptop for engineering students?

We hope this article has helped you to resolve the problem. Apart from PHP DOMDocument createAttribute () function, check other PHP-related topics.

Want to excel in Python? See our review of the best Python online courses 2022. If you are interested in Data Science, check also how to learn programming in R.

By the way, this material is also available in other languages:



Angelo Danburry

Berlin | 2022-11-26

Maybe there are another answers? What PHP DOMDocument createAttribute () function exactly means?. I just hope that will not emerge anymore

Manuel Robinson

Boston | 2022-11-26

Simply put and clear. Thank you for sharing. PHP DOMDocument createAttribute () function and other issues with PHP was always my weak point 😁. I am just not quite sure it is the best method

Julia Danburry

Shanghai | 2022-11-26

Maybe there are another answers? What PHP DOMDocument createAttribute () function exactly means?. Checked yesterday, it works!

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically