2424
2525from robot .api import logger
2626from robot .libraries .BuiltIn import BuiltIn
27- from robot .utils import (asserts , ET , ETSource , is_falsy , is_string , is_truthy ,
28- plural_or_not as s )
27+ from robot .utils import (asserts , ET , ETSource , is_bytes , is_falsy , is_string ,
28+ is_truthy , plural_or_not as s )
2929from robot .version import get_version
3030
3131
@@ -68,10 +68,11 @@ class XML(object):
6868 = Parsing XML =
6969
7070 XML can be parsed into an element structure using `Parse XML` keyword.
71- It accepts both paths to XML files and strings that contain XML. The
72- keyword returns the root element of the structure, which then contains
73- other elements as its children and their children. Possible comments and
74- processing instructions in the source XML are removed.
71+ The XML to be parsed can be specified using a path to an XML file or as
72+ a string or bytes that contain XML directly. The keyword returns the root
73+ element of the structure, which then contains other elements as its
74+ children and their children. Possible comments and processing instructions
75+ in the source XML are removed.
7576
7677 XML is not validated during parsing even if has a schema defined. How
7778 possible doctype elements are handled otherwise depends on the used XML
@@ -93,6 +94,8 @@ class XML(object):
9394 escaped by doubling it (``\\ \\ ``). Using the built-in variable ``${/}``
9495 naturally works too.
9596
97+ Note: Support for XML as bytes is new in Robot Framework 3.2.
98+
9699 = Using lxml =
97100
98101 By default this library uses Python's standard
@@ -584,7 +587,7 @@ def get_elements(self, source, xpath):
584587 | ${children} = | Get Elements | ${XML} | first/child |
585588 | Should Be Empty | ${children} | | |
586589 """
587- if is_string (source ):
590+ if is_string (source ) or is_bytes ( source ) :
588591 source = self .parse_xml (source )
589592 finder = ElementFinder (self .etree , self .modern_etree , self .lxml_etree )
590593 return finder .find_all (source , xpath )
0 commit comments