Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
80748727
Commit
80748727
authored
Aug 16, 2016
by
olivier R-D
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for pretty xml export
parent
a41a93af
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
opcua/common/xmlexporter.py
opcua/common/xmlexporter.py
+9
-4
No files found.
opcua/common/xmlexporter.py
View file @
80748727
...
@@ -5,6 +5,7 @@ format is the one from opc-ua specification
...
@@ -5,6 +5,7 @@ format is the one from opc-ua specification
import
logging
import
logging
from
collections
import
OrderedDict
from
collections
import
OrderedDict
import
xml.etree.ElementTree
as
Et
import
xml.etree.ElementTree
as
Et
from
xml.dom
import
minidom
from
opcua
import
ua
from
opcua
import
ua
from
opcua.ua
import
object_ids
as
o_ids
# FIXME needed because the reverse look up isn't part of ObjectIds Class
from
opcua.ua
import
object_ids
as
o_ids
# FIXME needed because the reverse look up isn't part of ObjectIds Class
...
@@ -47,7 +48,7 @@ class XmlExporter(object):
...
@@ -47,7 +48,7 @@ class XmlExporter(object):
# add all namespace uris to the XML etree; must be done after aliases are added
# add all namespace uris to the XML etree; must be done after aliases are added
self
.
_add_namespace_uri_els
(
uris
)
self
.
_add_namespace_uri_els
(
uris
)
def
write_xml
(
self
,
xmlpath
):
def
write_xml
(
self
,
xmlpath
,
pretty
=
True
):
"""
"""
Write the XML etree in the exporter object to a file
Write the XML etree in the exporter object to a file
Args:
Args:
...
@@ -57,10 +58,14 @@ class XmlExporter(object):
...
@@ -57,10 +58,14 @@ class XmlExporter(object):
"""
"""
# try to write the XML etree to a file
# try to write the XML etree to a file
self
.
logger
.
info
(
'Exporting XML file to %s'
,
xmlpath
)
self
.
logger
.
info
(
'Exporting XML file to %s'
,
xmlpath
)
try
:
if
pretty
:
rough_string
=
Et
.
tostring
(
self
.
etree
.
getroot
(),
'utf-8'
)
reparsed
=
minidom
.
parseString
(
rough_string
)
pretty_string
=
reparsed
.
toprettyxml
(
indent
=
" "
)
with
open
(
xmlpath
,
"wt"
)
as
f
:
f
.
write
(
pretty_string
)
else
:
self
.
etree
.
write
(
xmlpath
,
short_empty_elements
=
False
)
self
.
etree
.
write
(
xmlpath
,
short_empty_elements
=
False
)
except
TypeError
as
e
:
# TODO where to find which exceptions etree.write() raises?
self
.
logger
.
error
(
"Error writing XML to file: "
,
e
)
def
dump_etree
(
self
):
def
dump_etree
(
self
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment