如何使用python从xml文件中提取文本
我试图从这个xml文件中提取文本数据,但我不知道为什么我的代码不起作用。我怎样才能得到这个电话号码?请查看此XML文件以及我的代码格式。我正在尝试从此标记提取数据。提前谢谢:如何使用python从xml文件中提取文本,python,xml,Python,Xml,我试图从这个xml文件中提取文本数据,但我不知道为什么我的代码不起作用。我怎样才能得到这个电话号码?请查看此XML文件以及我的代码格式。我正在尝试从此标记提取数据。提前谢谢: <ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:voc="urn:hl7-org:v3/voc" xml
<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:voc="urn:hl7-org:v3/voc" xmlns:sdtc="urn:hl7-org:sdtc" xsi:schemaLocation="CDA.xsd">
<realmCode code="US"/>
<languageCode code="en-US"/>
<recordTarget>
<patientRole>
<addr use="HP">
<streetAddressLine>3345 Elm Street</streetAddressLine>
<city>Aurora</city>
<state>CO</state>
<postalCode>80011</postalCode>
<country>US</country>
</addr>
<telecom value="tel:+1(303)-554-8889" use="HP"/>
<patient>
<name use="L">
<given>Janson</given>
<given>J</given>
<family>Example</family>
</name>
</patient>
</patientRole>
</recordTarget>
</ClinicalDocument>
您的XML文档已指定名称空间,因此它类似于:
for country in tree.findall('.//{urn:hl7-org:v3}patientRole'):
number = country.find('{urn:hl7-org:v3}telecom').attrib['value']
print(number)
输出:
tel:+1(303)-554-8889
您的XML文档已指定名称空间,因此它类似于:
for country in tree.findall('.//{urn:hl7-org:v3}patientRole'):
number = country.find('{urn:hl7-org:v3}telecom').attrib['value']
print(number)
输出:
tel:+1(303)-554-8889
检查:检查:非常感谢您对@perl的解释非常感谢您对@perl的解释