Python读取具有多个名称的xml文件p

2024-10-17 08:32:07 发布

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

  <?xml version="1.0" encoding="UTF-8"?>
        <country:list version="3.0" xmlns:country="http://Some/www.home.com" xmlns:region="http://some/www.hello.com" xmlns:Location="http://Some/www.home.com">
            <country:Region111>
                <Some_child_tags>
                    <region:tag1 name="1">some contents in country:Region111 </region:tag1>

                    <tags>

                            .
                            .
                            .
                            .
                    </tags>
                    <region:tag1 name="2">Some other contents in country:Region111</region:tag1>
                </Some_child_tags>
            </country:Region111>

            <Location:Region222>
            <Some_child_tags>
                    <region:tag1 name="1">some contents in Location:Region222</region:tag1>
                    <tags>

                            .
                            .
                            .
                            .
                    </tags>
                    <region:tag1 name="2">Some other contents in Location:Region222</region:tag1>
                </Some_child_tags>
            </Location:Region222>
        </country:list>

I want to retrieve all the <region:tag1> tag contens and attribute values also that is comming under <country:Region111>...</country:Region111> not under <Location:Region222> ....</Location:Region222>. So the final output should be the following

^{pr2}$
      It should eliminate the <region:tag1> contents that is coming from <Location:Region222>.

Tags: thenameinchildhttpcontentstagslocation
1条回答
网友
1楼 · 发布于 2024-10-17 08:32:07

输入的XML文档应如下所示(有效):

<?xml version="1.0" encoding="UTF-8"?>
<country:list version="3.0" xmlns:country="http://Some/www.home.com" xmlns:region="http://some/www.hello.com">
<country:Region111>
     <Some_child_tags>
      <region:tag1>some contents</region:tag1>
     </Some_child_tags>
</country:Region111>
</country:list>

{a1}使用解决方案^ a1:

^{pr2}$

输出:

some contents

相关问题 更多 >