XML Tutorials Chapter 3 - XML syntax and rules

Page 1

Chapter 3: XML Syntax and Rules There are few rules and structure that you need follow while you design or create your XML document. It s easy to learn them and use into your application. <?xml version="1.0" encoding="UTF-8"?> <products> <product> <name>Apple iPhone 8S</name> <color>Red</color> <price>$950.00</price> <discount>$30.00</discount> </product> </products> You should notice in above example, there are two kind of details. <name> 1. Markup : 2. Values:

Apple iPhone 8S

Rule 1: Root Element in XML and Declaration It is necessary that you can use root element in your XML document. Without root element, you can t create any XML document or define any other elements within a XML document. Main rule about root element is that, you can use only one root element in your XML document. This root element must be on top of the page and it s also considered as parent of all other elements in your XML document.

<root> Your all other elements for XML document </root> Let s look into one example to understand <?xml version="1.0" encoding="UTF-8"?> <products> <product> <name>Sony Xperia R1 Dual</name> <color>Silver</color> <price>$650.00</price> <discount>$20.00</discount> </product>


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.