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
515bc60b
Commit
515bc60b
authored
Dec 06, 2016
by
mvdweert
Committed by
ORD
Dec 07, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[xmlimport] support nillable values
parent
e184dd32
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
1 deletion
+49
-1
opcua/common/xmlparser.py
opcua/common/xmlparser.py
+1
-1
tests/tests_xml.py
tests/tests_xml.py
+48
-0
No files found.
opcua/common/xmlparser.py
View file @
515bc60b
...
@@ -213,7 +213,7 @@ class XMLParser(object):
...
@@ -213,7 +213,7 @@ class XMLParser(object):
"""
"""
Parse the node val_el as a constant.
Parse the node val_el as a constant.
"""
"""
if
val_el
is
not
None
:
if
val_el
is
not
None
and
val_el
.
text
is
not
None
:
ntag
=
self
.
_retag
.
match
(
val_el
.
tag
).
groups
()[
1
]
ntag
=
self
.
_retag
.
match
(
val_el
.
tag
).
groups
()[
1
]
else
:
else
:
ntag
=
"Null"
ntag
=
"Null"
...
...
tests/tests_xml.py
View file @
515bc60b
...
@@ -309,6 +309,54 @@ class XmlTests(object):
...
@@ -309,6 +309,54 @@ class XmlTests(object):
o
=
self
.
opc
.
nodes
.
objects
.
add_variable
(
2
,
"xmlcustomunit32"
,
0
,
varianttype
=
ua
.
VariantType
.
UInt32
,
datatype
=
t
.
nodeid
)
o
=
self
.
opc
.
nodes
.
objects
.
add_variable
(
2
,
"xmlcustomunit32"
,
0
,
varianttype
=
ua
.
VariantType
.
UInt32
,
datatype
=
t
.
nodeid
)
self
.
_test_xml_var_type
(
o
,
"cuint32"
)
self
.
_test_xml_var_type
(
o
,
"cuint32"
)
def
test_xml_var_nillable
(
self
):
xml
=
"""
<UANodeSet xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamespaceUris>
</NamespaceUris>
<Aliases>
<Alias Alias="Boolean">i=1</Alias>
<Alias Alias="String">i=12</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
<Alias Alias="HasComponent">i=47</Alias>
</Aliases>
<UAVariable BrowseName="2:xmlstring" DataType="String" NodeId="ns=2;s=test_xml.string.nillabel" ParentNodeId="i=85">
<DisplayName>xmlstring</DisplayName>
<Description>xmlstring</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">i=85</Reference>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Value>
<uax:String></uax:String>
</Value>
</UAVariable>
<UAVariable BrowseName="2:xmlbool" DataType="Boolean" NodeId="ns=2;s=test_xml.bool.nillabel" ParentNodeId="i=85">
<DisplayName>xmlbool</DisplayName>
<Description>xmlbool</Description>
<References>
<Reference IsForward="false" ReferenceType="HasComponent">i=85</Reference>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
</References>
<Value>
<uax:Boolean></uax:Boolean>
</Value>
</UAVariable>
</UANodeSet>
"""
fp
=
open
(
'import-nillable.xml'
,
'w'
)
fp
.
write
(
xml
)
fp
.
close
()
# TODO: when the xml parser also support loading from string, remove write to file
_new_nodes
=
self
.
opc
.
import_xml
(
'import-nillable.xml'
)
var_string
=
self
.
opc
.
get_node
(
ua
.
NodeId
(
'test_xml.string.nillabel'
,
2
))
var_bool
=
self
.
opc
.
get_node
(
ua
.
NodeId
(
'test_xml.bool.nillabel'
,
2
))
self
.
assertEqual
(
var_string
.
get_value
(),
None
)
self
.
assertEqual
(
var_bool
.
get_value
(),
None
)
def
_test_xml_var_type
(
self
,
node
,
typename
,
test_equality
=
True
):
def
_test_xml_var_type
(
self
,
node
,
typename
,
test_equality
=
True
):
dtype
=
node
.
get_data_type
()
dtype
=
node
.
get_data_type
()
dv
=
node
.
get_data_value
()
dv
=
node
.
get_data_value
()
...
...
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