使用python将select xml数据解析为列

2024-05-21 01:39:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将多个XML文件解析成列/表,但是有些XML有不同的数据,有些不重要,而其他数据很重要。在

ie(XML数据):

<setId root="ABD6ECF0-DC8E"/>
<component>
            <section>
                <id root="F08C6A14-8165-458A-BDC8-0B5878EB814D"/>
                <code code="34069-5" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="HOW SUPPLIED SECTION"/>
                <title mediaType="text/x-hl7-title+xml">HOW SUPPLIED</title>
                <text>
                    <paragraph>RENESE (polythiazide) Tablets are available as:</paragraph>
                    <paragraph>1 mg white, scored tablets in bottles of 100 (NDC 0069-3750-66).</paragraph>
                    <paragraph>2 mg yellow, scored tablets in bottles of 100 (NDC 0069-3760-66).</paragraph>
                    <paragraph>4 mg white, scored tablets in bottles of 100 (NDC 0069-3770-66).</paragraph>
                </text>
                <effectiveTime value="20051214"/>
            </section>
        </component>

<component>
            <section>
                <id root="42CB916B-BB58-44A0-B8D2-89B4B27F04DF"/>
                <code code="34089-3" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="DESCRIPTION SECTION"/>
                <title mediaType="text/x-hl7-title+xml">DESCRIPTION</title>
                <text>
                    <paragraph>Renese<sup>&#174;</sup> is designated generically as polythiazide, and chemically as 2<content styleCode="italics">H</content>-1,2,4-Benzothiadiazine-7-sulfonamide, 6-chloro-3,4-dihydro-2-methyl-3-[[(2,2,2-trifluoroethyl)thio]methyl]-, 1,1-dioxide. It is a white crystalline substance, insoluble in water but readily soluble in alkaline solution.</paragraph>
                    <paragraph>Inert Ingredients: dibasic calcium phosphate; lactose; magnesium stearate; polyethylene glycol; sodium lauryl sulfate; starch; vanillin. The 2 mg tablets also contain: Yellow 6; Yellow 10.</paragraph>
                </text>
                <effectiveTime value="20051214"/>
            </section>
        </component>
        <component>
            <section>

                         <manufacturedProduct>
                         <manufacturedMedicine>
                            <code code="0069-3750" codeSystem="2.16.840.1.113883.6.69" codeSystemName="FDA" displayName="NDC"/>
                            <name>Renese</name>
                            <formCode code="C42998" codeSystem="2.16.840.1.113883.3.26.1.1" displayName="TABLET"/>
                         <manufacturedProduct/>
                         <manufacturedMedicine/>

我希望最终结果是这样(在setID、description和name中是列名):

集合ID

ABD6ECF0-DC8E

说明

Renese通常被指定为
聚噻嗪,化学形式为2H-1,2,4- 苯并噻二嗪-7-磺酰胺,6-氯- 2,2-2-甲基 -三氟乙基)硫代]甲基],1,1-二氧化物。它是一个 白色结晶物质,不溶于水,但 易溶于碱性溶液。在

姓名

蕾丝


Tags: 数据textintitlecodesectionrootxml
1条回答
网友
1楼 · 发布于 2024-05-21 01:39:44

如果我没弄错,您正试图解析从这个站点下载的XML:https://dailymed.nlm.nih.gov/dailymed/drugInfo.cfm?setid=abd6ecf0-dc8e-41de-89f2-1e36ed9d6535

实际上,它不是一个普通的XML,它是HL7类型的,特别是(版本3){urn:hl7组织:v3})一个。在

为了快速处理这个问题,有一个开源工具(Mirth:https://www.mirth.com/),它可以很好地完成这项工作(Iguana:http://www.interfaceware.com/iguana.html,商业)。 顺便谢谢你的帖子,这给了我一个测试“欢乐”工具的机会。在

实际上,您需要将xml转换为HL7V3格式以获取所需的信息。下面是我为您的xml和输出使用的通道的示例(https://www.dropbox.com/sh/ibosv56m0monmcj/AACL7t6ZKOi4P-Bwpi75KhUXa?dl=0)。在

关于更多信息,我建议你看这里:Convert XML to HL7 messages using Mirth Connect

如果您毕竟需要使用python,那么可以查看HL7(http://hl7apy.org/)和FIHR(https://pypi.python.org/pypi/fhir/0.0.4)包。在

对于使用python解析常规XML,这里描述了几种方法:How do I parse XML in Python?(我个人对beauthoulsoup和lxml很感兴趣)。在

希望能有所帮助。 祝你好运

相关问题 更多 >