7/2/08


Java and XML: intro

Let's consider PhoneBook.xml:

<?xml version="1.0"?>
<pb:PhoneBook xmlns:pb="http://www.epam.com/com/PhoneBook" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.epam.com/com/PhoneBook PhoneBook.xsd">
 <pb:BookRecord>
  <pb:id>0</pb:id>
  <pb:name>Alex</pb:name>
  <pb:address>Kuiv, Kominterna 28</pb:address>
  <pb:email>aillusions@gmail.com</pb:email>
  <pb:phone>+380664392111</pb:phone>
 </pb:BookRecord>
 <pb:BookRecord>
  <pb:id>1</pb:id>
  <pb:name>Zhanna</pb:name>
  <pb:address>Kuiv, Showkunenko 3</pb:address>
  <pb:email>estetka@mail.ru</pb:email>
  <pb:phone>+380666464111</pb:phone>
 </pb:BookRecord>
</pb:PhoneBook>

xsd file PhoneBook.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.epam.com/com/PhoneBook" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:element name="PhoneBook">
  <xsd:complexType>
   <xsd:sequence minOccurs="0" maxOccurs="unbounded">
    <xsd:element name="BookRecord">
     <xsd:complexType>
      <xsd:sequence minOccurs="0">
       <xsd:element type="xsd:int" name="id" />
       <xsd:element type="xsd:string" name="name" />
       <xsd:element type="xsd:string" name="address" />
       <xsd:element type="xsd:string" name="email" />
       <xsd:element type="xsd:string" name="phone" />
      </xsd:sequence>
     </xsd:complexType>
    </xsd:element>
   </xsd:sequence>
  </xsd:complexType>
 </xsd:element>
</xsd:schema>

xsl file PhoneBook.xsl:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <strong>
   <xsl:text>Value</xsl:text>
  </strong>
 </xsl:template>
</xsl:stylesheet>

No comments: