Plex Media Center for OS X Leopard

5.2.2. XML — XML markup parsing & generation

The XML module contains functions allowing the developer to easily parse, generate & manipulate data represented as XML markup. The XML functions can also be used when working with HTML data.

Note

The XML module builds on top of the lxml library, particularly the ElementTree classes. This documentation will help with fully understanding the capabilities of the XML module.

TODO: Link to lxml/etree docs

This module defines the following functions:

XML.Element(name, text=None, **kwargs)

Returns a new Element object with the given name, text and attributes.

Parameters:
  • name (str) – The tag name of the new element
  • text (str) – The text content of the new element
  • kwargs – A list of key-value pairs representing the element’s attributes
Return type:

Element

XML.ElementFromString(string, isHTML=False)

Returns a new Element object representing the given XML markup.

Parameters:
  • string (str) – A string containing XML markup
  • isHTML (bool) – Specifies whether the given string contains HTML or not (the parser is more forgiving of errors in HTML markup)
XML.ElementFromURL(url, isHTML=False, values=None, headers={}, cacheTime=None)

Behaves similarly to XML.ElementFromString(), but parses the result of a given HTTP request rather than a string.

Parameters:
  • url (str) – The URL to request XML markup from
  • isHTML (bool) – Specifies whether the given string contains HTML or not (the parser is more forgiving of errors in HTML markup)
  • values (dict) – The values to use if making a POST request
  • headers (dict) – Additional headers to include in the request
  • cacheTime (int) – The maximum number of seconds the response should be cached for
XML.StringFromElement(el, encoding="utf8", method=None)

Converts the given Element object into an XML or HTML string.

Parameters:
  • el (str) – The Element object to convert to a string representation
  • encoding (str) – The string encoding to use
  • method (str) – The method to use when generating the string - should be xml or html (if not provided, the framework will use the most appropriate method based on the type of the provided element)
Returns:

A string representation of the given Element object

Return type:

str

Previous topic

5.2.1. HTTP — Manages interaction with web services via HTTP

Next topic

5.2.3. JSON — JSON parsing and generation