Answer the question
In order to leave comments, you need to log in
How to search by attribute in xml file and display its child element?
It is necessary to search for the tag attribute in Python, preferably using the Element Tree library and display its child element r_variant.
Here is the xml code
<?xml version="1.0" encoding="UTF-8"?>
<root>
<model name="KS16">
<!--*******-->
<s_variant>KS-16S</s_variant>
<s_variant>KS16S</s_variant>
<s_variant>king 16s</s_variant>
<s_variant>kingsong 16s</s_variant>
<s_variant>KS16</s_variant>
<!--*******-->
<r_variant>KS16S</r_variant>
<r_variant>KS-16S</r_variant>
<r_variant>KS 16S</r_variant>
<r_variant>KS16</r_variant>
</model>
<model name="KS14">
<!--*******-->
<s_variant>KS-14S</s_variant>
<s_variant>KS14S</s_variant>
<s_variant>king 14s</s_variant>
<s_variant>kingsong 14s</s_variant>
<s_variant>KS14</s_variant>
<!--*******-->
<r_variant>KS14S</r_variant>
<r_variant>KS-14S</r_variant>
<r_variant>KS 14S</r_variant>
<r_variant>KS14</r_variant>
</model>
</root>
Answer the question
In order to leave comments, you need to log in
Easily. You need to parse the xml and iterate over the elements, checking the value of the attribute. Or use XPath to get the desired element by selector.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question