External API XML Change
In this article, we're going to go over what has changed in the XML return type for the External API from Cornerstone 7.4 to 7.5.
Due to an oversight within the XML return type of the External API, we are creating a change that addresses this. If you migrate from Pro 6.4 or Cornerstone 7.4 to the next minor release and you had the External API enabled you will be placed into Legacy mode by default. You will also receive a warning in the WordPress admin addressing this which is hopefully how you found this doc page. Legacy mode will run the XML processing exactly how it was in the prior version to avoid your site from breaking. However this will be removed in the future and this doc is in place to help you convert to the new system easily.
If you are using the External API, but not using the XML return type you can safely turn off legacy mode. Navigate to "Turning Off Legacy Mode" in this doc to follow the instructions.
What has changed
Initially the XML conversion to JSON placed the attributes in a format . The problem with this is that you can't access attributes if you are looping through a set of tags. Making certain XML's unusable in Cornerstone. To address this the structure is now as follows.
- Content from an xml tag (such as
<tag>My Content</tag>
) is now grabbed throughtag.content
. In the prior version it would be justtag
. - Attributes from an xml tag (such as
<tag my_attribute="My Attribute"></tag>
) is now grabbed throughtag.attr.my_attribute
. In the prior version it would betag_attr.my_attribute
. - Grabbing and looping tags works the same way.
Here is another example. Giving the following XML
<Jobs advertiser="Themeco" version="7.5.0">
<Fields>
<Field type="text" name="Category">
Software Hero
</Field>
...more Field tags
</Fields>
</Jobs>
- If we wanted to grab a
Jobs
attribute we would useJobs.attr.advertiser
. - If we wanted to loop through the
Field
in theFields
tag. We would useJobs.Fields.Field
this is unchanged from how it was. - If we wanted to grab the content of a
Field
tag while we were looping throughField
tags, we would use{{dc:looper:field key="content"}}
- If we wanted to grab an attribute of a
Field
tag while we were looping throughField
tags, we would use{{dc:looper:field key="attr.name"}}
. It was not possible to do this in the prior version
Please feel free to reach out to us in the Forum if you have any questions.
Turning Off Legacy Mode
Navigate to Theme Options > API
. Find the toggle XML Legacy Mode
and turn this off. Press save and you will be running the new mode.
See something inaccurate? Let us know