Tag Archives: XML

Standalone

The standalone declaration is a way of telling the parser to ignore any markup declarations in the DTD. The DTD is thereafter used for validation only.

  • The standalone directive is an optional attribute on the XML declaration.
  • Valid values are yes and no, where no is the default value.
  • The attribute is only relevant when a DTD is used. (The attribute is irrelevant when using a schema instead of a DTD.)
  • standalone=”yes” means that the XML processor must use the DTD for validation only. In that case it will not be used for default values for attributes , entity declarations and normalization
  • Note that standalone=”yes” may add validity constraints if the document uses an external DTD. When the document contains things that would require modification of the XML, such as default values for attributes, and standalone=”yes” is used then the document is invalid.
  • Standalone=”yes” may help to optimize performance of document processing.

XML Character Encoding

Source Encoding

• Conducted at time of parsing
• Cannot be changed during parser lifetime
• Types

  1. UTF-8 (php uses this type for internal document representation; bytes up to 21)
  2. US-ASCII (single byte)
  3. ISO-8859-1 (single byte; default)

Target Encoding

• Conducted at time of php passing data to xml handlers
• Target encoding initially set to same as source encoding
• Can be changed at any time

Characters not capable of source encoding cause an error

Characters not capable of target encoding are demoted (to “?”)

XML

XML stands for eXtensible Markup Language.

XML was designed to store and transport data.

XML was designed to be both human- and machine-readable.

Data format (“UNIVERSAL”) used for structured document exchange.

XML plays an important role in many different IT systems.

XML is often used for distributing data over the Internet.

It is important (for all types of software developers!) to have a good understanding of XML

Example

<?xml version="1.0" encoding="UTF-8"?>
<site>
 <name>PHPCodez</name>
 <url>phpcodez.com</url>
</site>

SimpleXML

SimpleXML is an extension that allows us to easily manipulate and get XML data.

SimpleXML provides the ability to iterate over items in an XML document, as well as
access items within it as if they were object properties

SimpleXML provides an easy way of getting an element’s name, attributes and textual content if you know the XML document’s structure or layout.

SimpleXML turns an XML document into a data structure you can iterate through like a collection of arrays and objects.

  • SimpleXML allows removal of attributes.
  • SimpleXML allows addition of new attributes.
  • SimpleXML allows removal of nodes.
  • SimpleXML allows addition of new nodes.

Modify XML node element value php

XML File – test.xml
===============
<?xml version=”1.0″ encoding=”UTF-8″?>
<PHPCodez>
<Update>
<Time>26</Time>
</Update>
</PHPCodez>

 

PHPCode

========

<?php
$xmlFIle    =       “test.xml”;
$xmlString       =  file_get_contents($xmlFIle);
$content=simplexml_load_string($xmlString);
echo $content->Update->Time;
$content->Update->Time = date(“Y-M-d h:i:s”);
$content->asXML($xmlFIle);
?>