User:Jarle Pahr/XML: Difference between revisions
Jarle Pahr (talk | contribs) (→lXML) |
Jarle Pahr (talk | contribs) (→XPath) |
||
Line 61: | Line 61: | ||
==XPath== | ==XPath== | ||
http://lxml.de/1.3/xpathxslt.html | |||
http://www.w3.org/TR/xpath/ | http://www.w3.org/TR/xpath/ |
Revision as of 16:14, 9 January 2014
Notes on Extensible Markup Language (XML): https://en.wikipedia.org/wiki/XML
http://stackoverflow.com/questions/3536893/what-are-the-pros-and-cons-of-xml-and-json
XML in Python
https://wiki.python.org/moin/PythonXml
http://docs.python.org/2/library/xml.etree.elementtree.html#module-xml.etree.ElementTree
http://www.boddie.org.uk/python/XML_intro.html
http://stackoverflow.com/questions/1912434/how-do-i-parse-xml-in-python
http://oreilly.com/catalog/pythonxml/chapter/ch01.html
https://wiki.python.org/moin/MiniDom
lXML
http://lxml.de/3.3/lxmldoc-3.3.0beta3.pdf#chapter.7
https://pypi.python.org/pypi/lxml
http://lxml.de/3.3/lxmldoc-3.3.0beta3.pdf
http://infohost.nmt.edu/tcc/help/pubs/pylxml/web/index.html
The packages ElementTree and lxml uses an "Element Tree" view of .xml files differing from the Document Object Model (DOM).
The Element class in lxml contains the following attributes:
- .tag: The name of the element.
- .text: The text inside the element, up to the first child element. Equals None if no text.
- .tail: The text following the element.
- .attrib: Python dictionary with the elements attributes and their values.
ElementTree methods:
Element.find(match): Finds first subelement matching the argument, which can be either a path or tag name.
Element.findall(elementtype) : Get all child elements of the type elementtype.
Element.get(name): get the attribute value of the attribute name.
Element.attrib.keys(): Show attribute keys of the element.
Element.iterfind(): Finds all matching (by tag or path) subelements and returns an iterable.
Element.items() : Returns attributes and their values Element.set(key, value) : Set attribute to value
XPath
http://lxml.de/1.3/xpathxslt.html
http://docs.python.org/3.3/library/xml.etree.elementtree.html#elementtree-xpath
root.findall("./country/neighbor")
http://effbot.org/zone/element-xpath.htm
http://www.w3.org/TR/xpath/#section-Introduction
Seee also:
- SBML
- JSON