You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to use the schema from here: PLMXML
plus plmxml_parameters.zip to create an XML document from python. In the zip file is an example output that I'm expecting. The schema has extensions on extensions, with different extension layers having attributes for the extension. How do I set the attributes on a python class when those attributes are in the extension?
I've tried multiple ways to use xsdata, but have only really managed to get this command to work with the code below: !xsdata plmxml_parameters.xsd --package com.siemens --structure-style single-package
Here's the code I'm using:
import com.siemens
import pprint
import datetime
from xsdata.formats.dataclass.context import XmlContext
from xsdata.formats.dataclass.serializers import XmlSerializer
from xsdata.formats.dataclass.serializers.config import SerializerConfig
from xsdata.formats.dataclass.serializers.writers import XmlEventWriter
from xsdata.formats.dataclass.serializers.writers import LxmlEventWriter
# Create initial container for XML objects
plmxml_container = com.siemens.Plmxml(language="en-us", schema_version="6", author="Mike", time=datetime.datetime.now().strftime("%H:%M:%S"), date=datetime.datetime.now().strftime("%Y-%m-%d"))
# Create Header and Product objects
# Define parameters by unit
velocity = com.siemens.Parameter(id="id" + str(1))
velocity.name = 'velocity'
# Define a parameter revision for some reason that uses the parameter unit
param_rev = com.siemens.ParameterDefinitionRevision(id="id" + str(2))
param_rev.master_ref=velocity.id
param_rev.revision="A"
# Define the parameter that uses the parameter revision
realparam = com.siemens.RealParameter(id="id" + str(3))
realparam.name="Airspeed"
realparam.definition_ref=param_rev.id
realparam.minimum=0
realparam.maximum=120
realparam.maximum_operator="lessThan"
realparam.goal=90
realparam.minimum_operator="greaterThan"
config = SerializerConfig(indent=" ", pretty_print=True)
context = XmlContext()
serializer = XmlSerializer(context=context, config=config, writer=XmlEventWriter)
serialize_this = com.siemens.Plmxml(
parameter = [velocity],
parameter_definition_revision = [param_rev],
real_parameter = [realparam]
)
print(serializer.render(serialize_this, ns_map={"": "http://www.plmxml.org/Schemas/PLMXMLSchema"}))```
And the result:
`<?xml version="1.0" encoding="UTF-8"?>
<PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema" language="en" languages="en">
<RealParameter id="id3" distributionFactor="1.0" definitionRef="id2" goal="90" minimum="0" maximum="120" minimumOperator="greaterThan" maximumOperator="lessThan"/>
<Parameter id="id1" distributionFactor="1.0"/>
<ParameterDefinitionRevision id="id2" revision="A" masterRef="id1" allowedValuesExhaustive="false"/>
</PLMXML>`
Note that the "name" value is missing from each of RealParameter and ParameterDefinition.
The text was updated successfully, but these errors were encountered:
I am attempting to use the schema from here: PLMXML
plus plmxml_parameters.zip to create an XML document from python. In the zip file is an example output that I'm expecting. The schema has extensions on extensions, with different extension layers having attributes for the extension. How do I set the attributes on a python class when those attributes are in the extension?
I've tried multiple ways to use xsdata, but have only really managed to get this command to work with the code below:
!xsdata plmxml_parameters.xsd --package com.siemens --structure-style single-package
Here's the code I'm using:
The text was updated successfully, but these errors were encountered: