Skip to content
Jonathan Shroyer edited this page Apr 17, 2020 · 19 revisions

Pages has robust support for pulling XML values. The following are different ways to access different parts of an XML file.

Get

If you need a direct full path then GET is used.

<?= data('volume-1/issue-1/tomo-01-069')->get('article/front/journal-meta/journal-title-group/journal-title'); ?>

Find

If there are no other conflicting labels then you can access the value directly using FIND. This is a massive time saver since you don't have to traverse through each level like you do with GET.

<?= data('volume-1/issue-1/tomo-01-069')->find('journal-title'); ?>

Attributes

If your XML uses attributes then you access the values using the filter for attributes.

<?= data('volume-1/issue-1/JSHD-201800011')->get('article/front/article-meta/article-id')->filter('@attributes', ['pub-id-type' => 'publisher-id']); ?>
<?= data('volume-1/issue-1/JSHD-201800011')->find('subj-group')->filter('@attributes', ['subj-group-type' => 'Article Type'])->subject; ?>

Adding Defaults

If you are using YAML with XML fallback you can set it to default to YAML, then fall back to XML.

$title = $this->title ?? $this->data('volume-1/issue-1/tomo-01-069')->get('article/front/article-meta/title-group/article-title');

Previous: Articles | Next: Resources

Clone this wiki locally