Posts

Showing posts with the label xml

Parse the namespace based XML using Python

In this blog, I am considering how to parser and modify the xml file using python. For example, I need to parser the following xml 1 (slightly modified for this blog) and need to write the modified xml to out.xml file. Here the country.xml <?xml version="1.0"?> <actors xmlns:fictional="http://characters.example.com" xmlns="http://people.example.com"> <actor type='T1'> <name>John Cleese</name> <fictional:character>Lancelot</fictional:character> <fictional:character>Archie Leach</fictional:character> </actor> <actor type='T2'> <name>Eric Idle</name> <fictional:character>Sir Robin</fictional:character> <fictional:character>Gunther</fictional:character> <fictional:character>Commander Clement</fictional:character> </actor> </actors> In ...

Learn XML Schema by Example: 2 Polymorphism

Image
In the previous blog, Learn XML Schema by Example: 1. Complex type , I introduced the very simple idea of ComplexType in Schema. In this blog, I am going to introduce idea of polymorphism which is one of the very important concept in Object orientation. As shown in the above figure, I need Address to be replaced by AUAddress or USAddress in the instance xml file. All the Address, USAddress and AUAddress are complex types in the XML schema. These types are defined in the address.xsd file as shown in the following code. <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns="http://www.ojitha.org/address" targetNamespace="http://www.ojitha.org/address" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:complexType name="AUAddress"> <xs:complexContent> <xs:extension base="Address"...

Learn XML Schema by Example: 1. Complex type

Image
XML Schema development is one of the major requirements for the Web services. It is time to get rid of the RPC style and move to DOCUMENT style. First of this series I would like to start with complex type. <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns="http://www.ojitha.org" targetNamespace="http://www.ojitha.org" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="process"> <xs:complexType> <xs:sequence> <xs:element name="person" type="personType"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="personType"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name=...