- Comment must appear after XML declaration.
- Comment may appear anywhere in a document
- Comment must not appear within attribute values.
- Comment cannot be nested inside the other comment.
CDATA
means, Character Data
. CDATA is defined as blocks of text that are not parsed
by the parser, but are otherwise recognized as markup<?xml version="1.0" encoding="UTF-8"?>
<student>
<!-- Some comment about the student -->
<first-name>George</first-name>
<phone.mobile>(011) 123-4567</phone.mobile>
<city />
<description>
<![CDATA[
<p>
<a href="/mylink/article1"><img style="float: left; margin-right: 5px;" height="80" src="/mylink/image" alt=""/></a>
Author Names
<br/><em>Date</em>
<br/>Paragraph of text describing the article to be displayed</p>
]]>
</description>
</student>
CDATA Start section
- CDATA begins with the nine-character delimiter <![CDATA[
CDATA End section
- CDATA section ends with ]]>
delimiter
CData section
- Characters inside CData
section are interpreted as characters, and not as markup.
It may contain markup characters <
, >
, and &
, but they are ignored by the XML processorCDATA
cannot contain the string ]]>
anywhere in the XML document
2. Nesting
is not allowed in CDATA sectionpart of the document
, while a comment is not
2. In CDATA we cannot include the string ]]>
, while in a comment --
3. CDATA content is visible on the web if we specify xmlns
attribute as http://www.w3.org/1999/xhtml
, even if the file is saved as .xml
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CDATA Example</title>
</head>
<body>
<h2>Using a Comment</h2>
<div id="commentExample">
<!--
You won't see this in the document
and can use reserved characters like
< > & "
-->
</div>
<h2>Using a CDATA Section</h2>
<div id="cdataExample">
<![CDATA[
You will see this in the document
and can use reserved characters like
< > & "
]]>
</div>
</body>
</html>
1. XML Syntactical whitespace - is whitespace required by the XML in order to delimitate XML constructs.
2. Insignificant Whitespace - is whitespace, that is not considered part of an element, if two elements are separated by just whitespace its considered insignificant.
3. Significant Whitespace - is whitespace that XML element attribute contains.
target
- Identifies the application to which the instruction is directed.
2. instruction
- A character that describes the information for the target
application to process.
...
PI's example in real XML document<?xml version="1.0" encoding="UTF-8"?>
<student>
<?sort alpha-ascending?>
<?textinfo whitespace is allowed ?>
<first-name>George</first-name>
<phone.mobile>(011) 123-4567</phone.mobile>
</student>
In this example we have two PIs
1. sort
with value - alpha-ascending
2. textinfo
with value - whitespace is allowed
...
Note: processing instructions can contain any data except the combination ?>
, which is interpreted as a closing delimiter<?php
$my_xml_data =
'<?xml version="1.0" encoding="UTF-8"?>
<student>
<?sort alpha-ascending?>
<?textinfo whitespace is allowed ?>
<first-name>George</first-name>
<phone.mobile>(011) 123-4567</phone.mobile>
</student>';
$xml = simplexml_load_string($my_xml_data);
$doc = dom_import_simplexml($xml)->ownerDocument;
$xpath = new DOMXPath($doc);
# prints "/* processing instructions */ ", the value of the first PI: textinfo
echo $xpath->evaluate('string(//processing-instruction("textinfo")[1])');
The output of the above code is the following:whitespace is allowed
UTF-8
- 8-bits are used to represent a character
2. UTF-16
- 16-bits are used to represent a character
...
UTF
stands for UCS Transformation Format
, and UCS itself means Universal Character Set
...
XML document example that has UTF-8
encoding<?xml version="1.0" encoding="UTF-8"?>
<student>
<first-name>George</first-name>
<phone.mobile>(011) 123-4567</phone.mobile>
</student>
Note: If an XML document has not specified encoding, the default is UTF-8
elements
, attributes
and data types
.
Here is how XML schema looks like<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="company">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:unsignedInt" />
<xs:element name="name" type="xs:string" />
<xs:element name="phone" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The XML schema is derived from the following XML:<company>
<id>2859385</id>
<name>Tanmay Patil</name>
<phone>(011) 123-4567</phone>
</company>
The XML schema is generated using the following online tool:https://www.liquid-technologies.com/online-xml-to-xsd-converter
JS
is to use !!
directives:<script>
change_asset_category('{!! $category_values !!}');
</script>
The result will be:<script>
change_asset_category('{"version":"vers","patch_level":"patc","bcp_dr":"bcp\/d"}');
</script>