Sei sulla pagina 1di 10

Introduction to XML and Python programming

1 © 2011 ANSYS, Inc. December 3, 2012


Agenda

• What is XML?
• What is Python?

2 © 2011 ANSYS, Inc. December 3, 2012


What is XML?
XML stands for EXtensible Markup Language
• XML is a markup language much like HTML
• XML was designed to carry data
• XML is designed to be self-descriptive
• XML tags are not predefined
– Each application has it’s own tags
• ACT has it’s own XML tags

Tags

XML is Everywhere
• XML is the most common tool for data transmissions between all sorts of applications
3 © 2011 ANSYS, Inc. December 3, 2012
What is XML? (2)
The Difference Between XML and HTML
• XML is not a replacement for HTML
• XML and HTML were designed with different goals:
• XML was designed to transport and store data, with focus on what data is
• HTML was designed to display data, with focus on how data looks
• HTML is about displaying information, while XML is about carrying
information
XML Does Not DO Anything
• XML was created to structure, store, and transport information
• It is just information wrapped in tags
• Intended software interprets the information from the tags
– Examples
• “extension” tag is used by ACT to interpret the following data as an
extension
• “toolbar” tag is used to define a toolbar and uses the “entry” tag to
create toolbar items

4 © 2011 ANSYS, Inc. December 3, 2012


Understanding the XML structure
Three common terms used to describe parts of an XML document:
• Tags
• Elements and
• Attributes
• A tag is the text between the left angle bracket ( <) and
the right angle bracket ( >)
– There are starting tags (such as <extension>) and
ending tags (such as </extension>)
• An element is the starting tag, the ending tag, and
everything in between
– Example: the <interface> element contains three child
elements: <images>, <callbacks>, and <toolbar>
• An attribute is a name-value pair inside the starting tag
of an element
– Example: name and icon are attributes of the <entry>
element
• A comment is between start tag (<!--) and end tag (-->)
– Comments are parsed by the XML reader

Refer to “ACT developers guide” for more details on various


tags/elements and attributes Using a good editor helps a lot!
!
5 © 2011 ANSYS, Inc. December 3, 2012
What is Python?

Python is a object-oriented, interpreted, and interactive programming language


Python code is interpreted and portable between platforms
Python combines remarkable power with very clear syntax
• It has modules, classes, exceptions, …
• There are interfaces to many system calls and libraries

IronPython is the Python Workbench uses


• IronPython is an implementation of Python for .NET, by Microsoft
• It brings new possibilities to the Python programmers
– Large .NET users’ community
– Many tools: debugging…
– Forums
– Libraries
– …
6 © 2011 ANSYS, Inc. December 3, 2012
Variables and Syntax
Variables
• Don’t need to be pre declared
• A variable can change type
Colon
• Required at the end of compound statement headers
(the first line of an if, while, for, etc.)
Whitespace
• Important only for the indentation level (i.e. the
whitespace at the very left of your statements).
Case-sensitivity
• Python is case-sensitive
• Variable names may mix upper- and lower-case
• Calling code must match the case exactly
• Python keywords are case-sensitive too
Comments
• Syntax # 1: # Comment
– Text after # is ignored in a single line
• Syntax # 2: “”” Comment “””
– Text between “”” “”” pairs is ignored

7 © 2011 ANSYS, Inc. December 3, 2012 ! Using a good editor helps a lot!
Variables and Syntax (2)
List
• The most versatile datatype in Python
• Comma-separated values between square
brackets
Operators
• Arithmetic operators: +, -, /, *,…
• Comparison Operators: ==, !=, >=,…
• Assignment operators: =, +=, -=, ...
• Logical operators: and, or, not
Flow Controls
• If-Else
• For
• While
Functions
• begin with the keyword def
• followed by the function name and parentheses
8 © 2011 ANSYS, Inc. December 3, 2012
Recommended References

Free materials
• http://www.python.org/
– Python download all formats
– Tutorial and documentation
• http://ironpython.codeplex.com/
– IronPython studio is free Microsoft SDK that allows you to manage your projects
and develop using native windows forms
• http://www.tutorialspoint.com/python/index.htm
• Free book - http://greenteapress.com/thinkpython/thinkCSpy.pdf
Recommended books
• Learning Python by Mark Lutz and David Ascher
• Python Pocket Reference by Mark Lutz
• IronPython in Action by Michael J.Ford and Christian Muirhead
– For people wanting to use Iron python to take advantage of the .NET framework

9 © 2011 ANSYS, Inc. December 3, 2012


Q/A

10 © 2011 ANSYS, Inc. December 3, 2012

Potrebbero piacerti anche