Creating an XML in PHP using DOMDocument

In this tutorial you will learn how to create XML documents using PHP’s DOMDocument class.
First things first.There are 3 things that you should always keep in mind about XML. In short, XML has 3 main components.

Elements, which we also call nodes. e.g.

<name />

Attributes e.g

<name type="first"/>

Here type is an attribute.
Data/text nodes

<name type="first">Johnson</name>

[...]

Read the rest of this entry >>

php, xml

Quick PHP Tip: How to parse CDATA sections using SimpleXML

Applies to:  simplexml_load_string and simplexml_load_file
Problem : SimpleXML does not parse text inside CDATA tags in an XML.
Consider the XML below:

 
$str = ‘<rootNode>’;
$str.=’<childNode>some text goes here</childNode>’;
$str.=’</rootNode>’;

To parse it we use following syntax:

$xml = simplexml_load_string($str);

On printing it outputs:

 
SimpleXMLElement Object
(
[childNode] => some text goes here
)

Thats OK. Now the same xml but this time the [...]

Read the rest of this entry >>

FAQ, php
9,565 spam comments
blocked by
Akismet