Skip to content

Commit e7289f1

Browse files
author
Steve Canny
committed
add opc/oxml.py module baseline
1 parent ed80ca6 commit e7289f1

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

opc/oxml.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# oxml.py
4+
#
5+
# Copyright (C) 2012, 2013 Steve Canny scanny@cisco.com
6+
#
7+
# This module is part of python-opc and is released under the MIT License:
8+
# http://www.opensource.org/licenses/mit-license.php
9+
10+
"""
11+
Classes that directly manipulate Open XML and provide direct object-oriented
12+
access to the XML elements.
13+
"""
14+
15+
from lxml import etree, objectify
16+
17+
18+
# configure objectified XML parser
19+
fallback_lookup = objectify.ObjectifyElementClassLookup()
20+
element_class_lookup = etree.ElementNamespaceClassLookup(fallback_lookup)
21+
oxml_parser = etree.XMLParser(remove_blank_text=True)
22+
oxml_parser.set_element_class_lookup(element_class_lookup)
23+
24+
25+
# ===========================================================================
26+
# functions
27+
# ===========================================================================
28+
29+
def oxml_fromstring(text):
30+
"""``etree.fromstring()`` replacement that uses oxml parser"""
31+
return objectify.fromstring(text, oxml_parser)

0 commit comments

Comments
 (0)