Анализатор DRF xml не может получить вложенный элемент списка (значение переопределяется) при разборе xml с пространствами имен - PullRequest
0 голосов
/ 14 января 2019

Я пытаюсь проанализировать список элементов, используя Django REST XMLParser. Парсер обрабатывает список элементов как один элемент. Вот XML:

<pa-structures:Question>
    <pa-structures:QuestionID>Q1</pa-structures:QuestionID>
    <pa-structures:SequenceNumber>1</pa-structures:SequenceNumber>
    <pa-structures:QuestionText>Is this patient home self-administering?</pa-structures:QuestionText>
    <pa-structures:DefaultNextQuestionID>Q2</pa-structures:DefaultNextQuestionID>
    <pa-structures:QuestionType>
        <pa-structures:Select>
            <pa-structures:SelectMultiple>N</pa-structures:SelectMultiple>
            <pa-structures:Choice>
                <pa-structures:ChoiceID>Q1C1</pa-structures:ChoiceID>
                <pa-structures:SequenceNumber>1</pa-structures:SequenceNumber>
                <pa-structures:ChoiceText>Yes</pa-structures:ChoiceText>
                <pa-structures:AdditionalFreeTextIndicator>NA</pa-structures:AdditionalFreeTextIndicator>
            </pa-structures:Choice>
            <pa-structures:Choice>
                <pa-structures:ChoiceID>Q1C2</pa-structures:ChoiceID>
                <pa-structures:SequenceNumber>2</pa-structures:SequenceNumber>
                <pa-structures:ChoiceText>No</pa-structures:ChoiceText>
                <pa-structures:AdditionalFreeTextIndicator>NA</pa-structures:AdditionalFreeTextIndicator>
            </pa-structures:Choice>
        </pa-structures:Select>
    </pa-structures:QuestionType>
</pa-structures:Question>
<pa-structures:Question>
    <pa-structures:QuestionID>Q2</pa-structures:QuestionID>
    <pa-structures:SequenceNumber>2</pa-structures:SequenceNumber>
    <pa-structures:QuestionText>Is the medication to be used to treat prophylaxis?</pa-structures:QuestionText>
    <pa-structures:QuestionType>
        <pa-structures:Select>
            <pa-structures:SelectMultiple>N</pa-structures:SelectMultiple>
            <pa-structures:Choice>
                <pa-structures:ChoiceID>Q2C1</pa-structures:ChoiceID>
                <pa-structures:SequenceNumber>1</pa-structures:SequenceNumber>
                <pa-structures:ChoiceText>Yes</pa-structures:ChoiceText>
                <pa-structures:AdditionalFreeTextIndicator>NA</pa-structures:AdditionalFreeTextIndicator>
                <pa-structures:NextQuestionID>Q3</pa-structures:NextQuestionID>
            </pa-structures:Choice>
            <pa-structures:Choice>
                <pa-structures:ChoiceID>Q2C2</pa-structures:ChoiceID>
                <pa-structures:SequenceNumber>2</pa-structures:SequenceNumber>
                <pa-structures:ChoiceText>No</pa-structures:ChoiceText>
                <pa-structures:AdditionalFreeTextIndicator>NA</pa-structures:AdditionalFreeTextIndicator>
                <pa-structures:NextQuestionID>Q4</pa-structures:NextQuestionID>
            </pa-structures:Choice>
        </pa-structures:Select>
    </pa-structures:QuestionType>
</pa-structures:Question>
<pa-structures:Question>
    <pa-structures:QuestionID>Q3</pa-structures:QuestionID>
    <pa-structures:SequenceNumber>3</pa-structures:SequenceNumber>
    <pa-structures:QuestionText>When was or will the surgery be done?</pa-structures:QuestionText>
    <pa-structures:DefaultNextQuestionID>Q6</pa-structures:DefaultNextQuestionID>
    <pa-structures:QuestionType>
        <pa-structures:Date>
            <datatypes:IsDateTimeRequired>N</datatypes:IsDateTimeRequired>
        </pa-structures:Date>
    </pa-structures:QuestionType>
</pa-structures:Question>
<pa-structures:Question>
    <pa-structures:QuestionID>Q4</pa-structures:QuestionID>
    <pa-structures:SequenceNumber>4</pa-structures:SequenceNumber>
    <pa-structures:QuestionText>Is the medication to be used for treatment of DVT?</pa-structures:QuestionText>
    <pa-structures:QuestionType>
        <pa-structures:Select>
            <pa-structures:SelectMultiple>N</pa-structures:SelectMultiple>
            <pa-structures:Choice>
                <pa-structures:ChoiceID>Q4C1</pa-structures:ChoiceID>
                <pa-structures:SequenceNumber>1</pa-structures:SequenceNumber>
                <pa-structures:ChoiceText>Yes</pa-structures:ChoiceText>
                <pa-structures:AdditionalFreeTextIndicator>NA</pa-structures:AdditionalFreeTextIndicator>
                <pa-structures:NextQuestionID>Q5</pa-structures:NextQuestionID>
            </pa-structures:Choice>
            <pa-structures:Choice>
                <pa-structures:ChoiceID>Q4C2</pa-structures:ChoiceID>
                <pa-structures:SequenceNumber>2</pa-structures:SequenceNumber>
                <pa-structures:ChoiceText>No</pa-structures:ChoiceText>
                <pa-structures:AdditionalFreeTextIndicator>NA</pa-structures:AdditionalFreeTextIndicator>
                <pa-structures:NextQuestionID>Q6</pa-structures:NextQuestionID>
            </pa-structures:Choice>
        </pa-structures:Select>
    </pa-structures:QuestionType>
</pa-structures:Question>
<pa-structures:Question>
    <pa-structures:QuestionID>Q5</pa-structures:QuestionID>
    <pa-structures:SequenceNumber>5</pa-structures:SequenceNumber>
    <pa-structures:QuestionText>What is the patient's weight (in pounds)?</pa-structures:QuestionText>
    <pa-structures:DefaultNextQuestionID>Q6</pa-structures:DefaultNextQuestionID>
    <pa-structures:QuestionType>
        <pa-structures:Numeric>
            <pa-structures:IsNumeric>Y</pa-structures:IsNumeric>
        </pa-structures:Numeric>
    </pa-structures:QuestionType>
</pa-structures:Question>
<pa-structures:Question>
    <pa-structures:QuestionID>Q6</pa-structures:QuestionID>
    <pa-structures:SequenceNumber>6</pa-structures:SequenceNumber>
    <pa-structures:QuestionText>Describe result of Warfarin use (include INR and date drawn) or reason why patient can't use Warfarin.
    </pa-structures:QuestionText>
    <pa-structures:DefaultNextQuestionID>END</pa-structures:DefaultNextQuestionID>
    <pa-structures:QuestionType>

Если я получу доступ к тегу QuestionType, я получу информацию Q6. Я не могу получить доступ к информации от q1 до q5. Я получаю доступ к тегу вопроса по этому коду:

response_data.get('{http://www.ncpdp.org/schema/transport}Body', {})\
    .get('{http://www.ncpdp.org/schema/transport}PAInitiationResponse', {})\
    .get('{http://www.ncpdp.org/schema/script}Response', {})\
    .get('{http://www.ncpdp.org/schema/pa-structures}ResponseStatus', {}).data.get('{http://www.ncpdp.org/schema/pa-structures}Open', None)

Я использую класс XMLParser drf.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...