Skip to content

Commit 2641bcb

Browse files
committed
Added optional variable to allow for custom root keys
1 parent 6874647 commit 2641bcb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

rss_parser/_parser.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ def to_xml(data: str, *args, **kwargs):
2828
return parse(str(data), *args, **kwargs)
2929

3030
@classmethod
31-
def parse(cls, data: str, *, schema: Optional[Type[XMLBaseModel]] = None) -> XMLBaseModel:
31+
def parse(cls, data: str, *, schema: Optional[Type[XMLBaseModel]] = None, root_key: str = "") -> XMLBaseModel:
3232
"""
3333
Parse XML data into schema (default: RSS 2.0).
3434
3535
:param data: string of XML data that needs to be parsed
3636
:return: "schema" object
3737
"""
3838
root = cls.to_xml(data)
39-
root, schema = cls.check_schema(root)
39+
if not isinstance(schema, XMLBaseModel):
40+
root, schema = cls.check_schema(root)
41+
else:
42+
root = root.get(root_key, root)
4043

4144
return schema.parse_obj(root)

0 commit comments

Comments
 (0)