Complex namespaces
See original GitHub issueThis hope that is not and issue but rather lack of documentation. I have such document:
<response
xmlns="..."
xmlns:c="..............."
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="xxxxxxxx"
>
<object>
<name xml:lang="en">Some value</name>
<name xml:lang="fr">Some value</name>
<c:contact>
<c:contactName xml:lang="en">Some value</c:contact-name>
</c:contact>
</object>
</response>
This is code snippet that I tried to achieve it but it does not work.
_ns_map = {
None: "...",
"xml": "http://www.w3.org/XML/1998/namespace",
"c": "............"
}
_serializer_config = config = SerializerConfig(
pretty_print=True,
schema_location="xxxxxxxx",
)
_serializer = XmlSerializer(config=_serializer_config)
@dataclass
class Contact:
contact_name: str = field(metadata=dict(type="Attribute", name="contact"))
class Meta:
namespace = "c"
@dataclass
class Name:
lang: str = field(metadata=dict(type="Attribute", name="lang"))
value: str = field(default=None)
class Meta:
namespace = "xml"
@dataclass
class Object:
id: str
name: List[Name] = field(default_factory=list, metadata={"type": "Element"})
contact: Contact = field(default=None)
class Meta:
namespace = None
@dataclass
class Response:
object: Object = field(metadata=dict(namespace=None))
class Meta:
name = "response"
namespace = _ns_map[None]
def render(self) -> str:
return _serializer.render(self, ns_map=_ns_map)
if __name__ == '__main__':
print(
Response(object=Object(
id="12121",
name=[Name(lang="en", value="Some value")],
contact=Contact(contact_name="Some value")
)).render()
)
Could you help me to write code that would print proper document structure?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
CSS Practice: Namespaces in Complex Projects
Working in complex projects or in projects that don't provide a good overview of forthcoming page types and elements may require a defensive ......
Read more >XSD Namespaces - XML Schema Tutorial - Liquid Technologies
This tutorial explains the use of Namespaces with XML Schema (XSD). ... This article gives an overview of the complex nature of using...
Read more >Kubernetes architecture: How to use hierarchical namespaces ...
Hierarchical namespaces make it easier to manage individual tenants' permissions and capabilities in a multitenant Kuberentes architecture.
Read more >XML Schema: Understanding Namespaces - Oracle
Moving to XML Schema? This introduction to namespaces will help you understand one of its more important elements.
Read more >Adding namespaces, element declarations, and complex ...
Use the namespace pane on the Types tab to add namespaces, element declarations, and complex types to an XML profile.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s not necessary, the namespace uri
http://www.w3.org/XML/1998/namespace
and it’s prefixxml
are both reserved and bound by the xml specification and doesn’t need to be declared in the document itself.Putting it all together