Skip to content

Complex xml structure #7

Answered by Rogdham
hballesteross asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, that's an interesting use case!

For a possible solution, let me assume that you wants your results to be returned as a dataclass instance. Let's use the following code to define the dataclass:

from dataclasses import dataclass
from typing import Optional

@dataclass
class Cpe:
    value: str
    distrito: Optional[str] = None
    concelho: Optional[str] = None
    fregesia: Optional[str] = None
    localidade: Optional[str] = None

Note: I'm not sure if the freguesia VS fregesia spellings are typos or not, the code here works with your provided XML where there is FREGESIA and FREGUESIA_NOME tags.

Now what I will do is to create a generic handler that will handle nodes of name DIST…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@hballesteross
Comment options

@hballesteross
Comment options

@hballesteross
Comment options

Answer selected by hballesteross
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants