Tutorial PHP

PHP INICIO Introducción PHP Instalación de PHP Sintaxis PHP Comentarios PHP Variables PHP PHP Echo / Imprimir Tipos de datos PHP Cadenas PHP Números PHP Matemáticas PHP Constantes PHP Operadores PHP PHP Si... Más... Elseif Cambio de PHP Bucles de PHP Funciones PHP Matrices de PHP Superglobales de PHP PHP expresión regular

Formularios PHP

Manejo de formularios PHP Validación de formulario PHP Formulario PHP requerido Formulario PHP URL/Correo electrónico Formulario PHP completo

PHP Avanzado

Fecha y hora PHP PHP Incluir Manejo de archivos PHP Archivo PHP Abrir/Leer Archivo PHP Crear/Escribir Carga de archivos PHP Cookies PHP Sesiones PHP Filtros PHP Filtros PHP avanzados Funciones de devolución de llamada de PHP PHPJSON Excepciones de PHP

POO de PHP

PHP ¿Qué es la programación orientada a objetos? Clases PHP/Objetos Constructor PHP Destructor PHP Modificadores de acceso de PHP Herencia de PHP Constantes PHP Clases abstractas de PHP Interfaces PHP Características de PHP Métodos estáticos de PHP Propiedades estáticas de PHP Espacios de nombres de PHP Iterables de PHP

Base de datos MySQL

Base de datos MySQL Conexión MySQL MySQL Crear base de datos Crear tabla MySQL MySQL Insertar datos MySQL Obtener la última identificación MySQL Insertar Múltiples MySQL preparado Datos seleccionados de MySQL mysql donde MySQL Ordenar por MySQL Eliminar datos Datos de actualización de MySQL Límite de datos de MySQL

PHPXML _

Analizadores PHP XML Analizador PHP SimpleXML PHP SimpleXML - Obtener PHP XML Expatriados PHP XML DOM

PHP -AJAX

Introducción a AJAX AJAXPHP Base de datos AJAX XML AJAX Búsqueda en vivo de AJAX Encuesta AJAX

Ejemplos de PHP

Ejemplos de PHP Compilador PHP Cuestionario de PHP Ejercicios PHP Certificado PHP

Referencia PHP

Descripción general de PHP Matriz de PHP Calendario PHP Fecha PHP Directorio PHP Error PHP Excepción PHP Sistema de archivos PHP Filtro PHP PHPFTP PHPJSON Palabras clave PHP PHP Libxml Correo PHP Matemáticas PHP PHP misceláneo PHP MySQLi Red PHP Control de salida de PHP PHP expresión regular PHP SimpleXML flujo PHP Cadena PHP Manejo de variables de PHP Analizador PHP XML código postal de PHP Zonas horarias de PHP

Función PHP __construct()

❮ Referencia PHP SimpleXML

Ejemplo

Cree un objeto SimpleXMLElement a partir de una cadena:

<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;

$xml=new SimpleXMLElement($note);
echo $xml->asXML();
?>

Definición y uso

La función __construct() crea un nuevo objeto SimpleXMLElement.


Sintaxis

SimpleXMLElement::__construct(data, options, data_is_url, ns, is_prefix)

Valores paramétricos

Parameter Description
data Required. Specifies A well-formed XML string or the path or URL to an XML document if data_is_url is TRUE
options Optional. Specifies additional Libxml parameters. Is set by specifying the option and 1 or 0 (TRUE or FALSE, e.g. LIBXML_NOBLANKS(1))

Possible values:

  • LIBXML_COMPACT - Activate nodes allocation optimization (may speed up application)
  • LIBXML_DTDATTR - Set default DTD attributes
  • LIBXML_DTDLOAD - Load external subset
  • LIBXML_DTDVALID - Validate with the DTD
  • LIBXML_NOBLANKS - Remove blank nodes
  • LIBXML_NOCDATA - Merge CDATA as text nodes
  • LIBXML_NOEMPTYTAG - Expand empty tags (e.g. <br/> to <br></br>), only available in the DOMDocument->save() and DOMDocument->saveXML() functions
  • LIBXML_NOENT - Substitute entities
  • LIBXML_NOERROR - Do not show error reports
  • LIBXML_NONET - Disable network access while loading documents
  • LIBXML_NOWARNING - Do not show warning reports
  • LIBXML_NOXMLDECL - Drop the XML declaration when saving a document
  • LIBXML_NSCLEAN - Remove redundant namespace declarations
  • LIBXML_PARSEHUGE - Sets XML_PARSE_HUGE flag, which relaxes any hardcoded limit from the parser. This affects limits like maximum depth of a document and limits of the size of text nodes
  • LIBXML_XINCLUDE - Implement XInclude substitution
  • LIBXML_ERR_ERROR - Get recoverable errors
  • LIBXML_ERR_FATAL - Get fatal errors
  • LIBXML_ERR_NONE - Get no errors
  • LIBXML_ERR_WARNING - Get simple warnings
  • LIBXML_VERSION - Get libxml version (e.g. 20605 or 20617)
  • LIBXML_DOTTED_VERSION - Get dotted libxml version (e.g. 2.6.5 or 2.6.17)
data_is_url Optional. TRUE specifies that data is a path/URL to an XML document instead of string data. Default is FALSE
ns Optional. Specifies a namespace prefix or URI
is_prefix Optional. Specifies a Boolean value. TRUE if ns is a prefix. FALSE if ns is a URI. Default is FALSE


Detalles técnicos

Valor devuelto: Devuelve un objeto SimpleXMLElement que representa datos
Versión PHP: 5.0+
Registro de cambios de PHP: PHP 5.2.0: Se agregaron los parámetros opcionales ns e is_prefix .
PHP 5.1.2: Se agregaron las opciones opcionales y los parámetros data_is_url .

Más ejemplos

Supongamos que tenemos el siguiente archivo XML, " note.xml ":

<?xml version="1.0" encoding="UTF-8"?>
<note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>

Ejemplo

Cree un objeto SimpleXMLElement a partir de una URL:

<?php
$xml=new SimpleXMLElement("note.xml", 0, TRUE);
echo $xml->asXML();
?>

❮ Referencia PHP SimpleXML