0

I have the following xml:

<assets>
    <asset type="full">
        <file_name>WME__HD_2CH_EN_16X9_178_2398_FINAL.mov</file_name>
    </asset>
    ...
</assets>

I have multiple asset blocks, so I need to reference the attribute type = "full". This is what I currently have to reference them all --

node.xpath("//t:assets/t:asset/t:file_name/text()", 
            namespaces={'t':'http://apple.com/itunes/importer'})

How would I reference only the asset with type = "full" ?

3 Answers 3

2

You can add the [@type="full"] attribute selector onto t:asset:

node.xpath("//t:assets/t:asset[@type='full']/t:file_name/text()", 
        namespaces={'t':'http://apple.com/itunes/importer'})
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

node.xpath("//t:assets/t:asset[@type='full']/t:file_name/text()", 
        namespaces={'t':'http://apple.com/itunes/importer'})

@ notation is used to select attributes through xpath.

So, t:asset[@type='full'] means select all asset element that have attribute type and value full.

Take a look here xpath synatx.

Comments

0
node.xpath("//t:assets/t:asset[@type='full']/t:file_name/text()", 
        namespaces={'t':'http://apple.com/itunes/importer'})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.