How to keep processing instructions of xml file in SDL Tridion?
Asked Answered
L

2

7

I am trying to add a processing instructions to my xml file in the source view of component xml. For example:

<?altova_sps C:\Users\src\sps\2012\spsfile.sps?>
<my_element xmlns="uuid:8d903098-e607-4d96-90a7-14d2d188dab7">
  ...
</my_element>

After I click on Save, Tridion CME automatically removed the processing instruction. Is there a way to change this behavior?

(I want to add the processing instruction so that I can open the xml file with XMLSpy in Authentic View using WebDAV)

Lighting answered 1/10, 2012 at 16:12 Comment(0)
D
3

I have researched this a bit, and I am not convinced this can be done from within the CMS. However you can probably achieve this by creating an HTTPModule or Proxy or some form which transforms the requests and responses made to the /webdav directory of the CME.

Conceptually when a request is made by XMLSpy, the new module would pre-pend the desired instruction to the XML based on the item being a Component and the Schema it is based on. Then when you save (POST) the data back it would need to strip it out again. This would leave the XML structure in the format that SDL Tridion requires.

Hope that helps

Chris

Decentralization answered 3/10, 2012 at 0:55 Comment(2)
Thanks Chris for all the research and answers. I understand the challenges as well. I am just wondering whether Tridion CME can keep my processing instructions after I added it in source view. That would save all the trouble. Is there a way to submit a feature request to Tridion?Lighting
You can submit the idea via ideas.sdltridion.com or an enhancement request with SDL Tridion Customer Support - But as stated by @Nuno, the XML you are seeing is only the content node, and not the complete XML, so it will always be invalid to save the processing instruction there, so I don't think it is likely that they will implement it. But it is worth trying. Good luck.Decentralization
D
2

I am posting this as an idea - although I can't get it do do quite what you want. I have written an EventHandler to manipulate the XML recieved by XMLSpy (and all clients including the CME at this point)

using System;
using System.Text;
using System.Xml;
using Tridion.ContentManager.Extensibility.Events;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.ContentManagement;
using System.IO;

namespace UrbanCherry.Net.SDLTridion.EventHandlers
{
    [TcmExtension("AppendAuthenticHeaders")]
    public class AppendAuthenticHeaders : TcmExtension
    {
        public AppendAuthenticHeaders()
        {
            Subscribe();
        }

        public void Subscribe()
        {
            EventSystem.Subscribe<Component, LoadEventArgs>(AppendAuthenticHeader, EventPhases.Processed);
        }

        private void AppendAuthenticHeader(Component source, LoadEventArgs args, EventPhases phase)
        {
            if (source.ComponentType != ComponentType.Multimedia)
            {
                XmlDocument newXml = new XmlDocument();
                newXml.LoadXml("<?altova_sps C:\\Users\\src\\sps\\2012\\spsfile.sps?>" + source.Content.OuterXml);
                source.Content = newXml.DocumentElement;
            }
        }


    }
}

I tried manipulating the output (by replacing a string), and it does show up in XMLSpy via WebDAV. The problem I have is that adding the processing instruction falls outside of the DocumentElement, so never makes it into the new XML.

So I know this does not solve your challenge - but perhaps someone else knows of an event which would allow you to append the instruction when the XML is loaded via the WebDAV cartridge in a similar manner.

Hope someone else can help you close this - I will dig a little more if I have time

Decentralization answered 1/10, 2012 at 23:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.