Think of a [] in an XPath as similar to a WHERE clause in an SQL statement, which is to say a filter.

/ADI/Asset/Asset/Metadata suggests that you want some asset metadata nodes. I'm going to assume that's correct for now.

But we only want metadata nodes where AMS/@Asset_Class equals poster. This is a filter.

/ADI/Asset/Asset/Metadata[ AMS/@Asset_Class = "poster" ]

Since this is a nested collection of assets, maybe you want to look any depth.

//Asset/Metadata[ AMS/@Asset_Class = "poster" ]

With the above, the asset name would be found at relative path AMS/@Asset_name. App_Data would return rows of metadata.


Is the asset metadata really what you want, though? If you wanted the whole asset instead of just its metadata (e.g. if you wanted to access the asset's content), you should use one of the following instead:

/ADI/Asset/Asset[ Metadata/AMS/@Asset_Class = "poster" ]
//Asset[ Metadata/AMS/@Asset_Class = "poster" ]

With these, the asset name would be found at relative path Metadata/AMS/@Asset_name. Metadata/App_Data would return rows of metadata. Content/@Value would return the poster image.


As a side note, an example of multiple [] in an XPath,

//Asset[ AMS/@Asset_Class = "package" and AMS/@Asset_Name = "some_pack +age" ]/Asset[ Metadata/AMS/@Asset_Class = "poster" ]

This would return the poster asset for a specific package.


In reply to Re: XML Parsing and Xpath confusion by ikegami
in thread XML Parsing and Xpath confusion by naChoZ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.