4

I have the below xml and i want to add an attribute to the node NavigationTreeItem in design view .. I don't see any options in schema to add attribute to the element ..any suggestions ?

 <TreeRoot xmlns="uuid:DE1E3836-4022-4299-BAFF-EE597A4D91C6">
  <ToolTitle>Job Search</ToolTitle>
  **<NavigationTreeItem>**
    <ParentLink>
      <Title>Job Search</Title>
      <URL xlink:type="simple" xlink:href="/JobSearch/JobSearch.aspx" xmlns:xlink="http://www.w3.org/1999/xlink"></URL>
    </ParentLink>
  </NavigationTreeItem>
</TreeRoot>

Want to get

**<NavigationTreeItem id="1">**
5

SDL Tridion Schemas can be divided in two categories, a Tridion Web Schema and a W3C Schema.

The first variant (also known as a Simple Schema) does not allow attributes and only accepts certain data types. The second variant (also known as Complex Schema) will allow you anything supported by http://www.w3.org/2001/XMLSchema. But W3C Schemas don't have a design tab (you have to edit the Schema directly in the source tab or use an external editor via WebDAV), and Components based on such a Schema, don't have a form based UI (you have to edit the XML directly in the source tab of the Component or use an external editor via WebDAV).

That all being said, if you need to have this XML and you have a way of editing it, a W3C Schema is definitely the way to go, since it will ensure your XML is validated on save of the Component.

Alternative solution

As an alternative, you could consider creating an id element and use XSLT to transform your Tridion XML into the required XML (at render/publishing time in a TBB for example), while still continue to use Tridion Web Schemas. But this won't work if you want to update the XML of the Component with the outputted XML of course.

| improve this answer | |
  • 1
    Thanks for the reply.. The content should be editable in the design view as per the client request( they manage the content). So i am thinking to add one more element like <id>1</id> to each <NavigationTreeItem> . Will post how it works. – Vani Oct 7 '14 at 15:02
  • 1
    The difference between attributes and elements is really only semantic (apart from the difference in size) so I'd suggest you go with elements as Bart suggests and just use them in your code instead - don't even transform in TBBs. You can still do XPath using elements. Unless of course you're trying to produce specific XML for a third party tool. – Rob Stevenson-Leggett Oct 7 '14 at 16:11
  • OK .. i added a new element and <NavigationTreeItem> <id>6</id> <ParentLink> and accessing in the XSLT , it works fine. Thanks all for the inputs. – Vani Oct 7 '14 at 17:02
5

"Simple Schemas" don't support attributes, only elements.

You can modify the Source tab of the Schema to add the attribute, but be aware that it will change it to a "Complex Schema" - meaning you will not be able to use the form-based UI to edit Components based on said Schema. You will only be able to edit it in the Source tab or through the API.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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