2

Using XPath, how to get the required fields? my bundle XML is as below.

<tcm:Metadata>
<Metadata xmlns="http://www.mycompany.com/tridion/schema/publish_bundle_schema">
  <my_workflow_metadata>
    <workflow_release xlink:href="tcm:84-3941-1024" xlink:title="Non-Release" xmlns:xlink="http://www.w3.org/1999/xlink">Non-Release</workflow_release>
    <approval_tracking_id>TGT-xxxx</approval_tracking_id>
  </my_workflow_metadata>
</Metadata>

  • I am able to fetch other values as below ex : var bundleName = $xml.getInnerText(xmlDoc, "/tcm:*/tcm:Data/tcm:Title");

but, for metadata I am facing issues. var workflow_metadata = $xml.selectSingleNode(xmlDoc, "/tcm:*/tcm:Data/tcm:Metadata"); is giving me all the metadata values. I would like to know the correct approach.

3
  • The required (mandatory) fields are defined in the Schema. I don't see how you can get that info from the XML source (via XPath). But required fields do present an asterisk, which you might be able to detect. What functionality do you want to offer for the required fields? Apr 1, 2015 at 7:58
  • @AlvinReyes : I am writing a GUI Extenstion to display some bundle properties like Bundlename, its metadata etc when you click on a particular bundle.
    – Pari
    Apr 1, 2015 at 9:13
  • Could give some more information about where this functionality has to work (command, custom view, ...) and what you expect to do? I believe there could be a more easy way to get your information than through the full item xml. Aug 21, 2015 at 17:01

1 Answer 1

3

Any nodes underneath tcm:Metadata is in the namespace of your Schema. So your XPath would need to use a custom prefix and you will need to define the namespace for that prefix in the 'namespaces' parameter to getInnerText.

Since you are writing a GUI Extension to display the metadata, you will probably want to read the namespace and the field labels from the Schema, since the Schema is going to be different for everyone.

It's up to you if you want the Bundle metadata to be leading (i.e. loop through the values and look up the label etc. in the Schema) or the Schema (loop through the Schema fields and find the corresponding value in the Bundle). Both are perfectly valid. Remember that the Bundle might be out of sync with the Schema if the Schema has been modified since the Bundle was created.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.