4

I am trying to remove the value of one field from my component through core service. Consider I have a field removeme in my component.

I have tried

 ComponentData c = client.Read("tcm:30-47499", new ReadOptions()) as ComponentData;                  
 // Console.WriteLine("Component source:" + c.Content);
 System.Xml.XmlDocument doc = new  System.Xml.XmlDocument();
 doc.LoadXml(c.Content);
 System.Xml.XmlNodeList elemList = doc.GetElementsByTagName("removeme");
 doc.RemoveChild(elemList[0]);

I want to remove the field removeme from component and save it.

Could some one tell me how to do that.

5

The Core Service allows to use partial xml. When you omit a node the CM thinks you do not want to change that node.

The way to clear the field contents is to send an send empty removeme node. Like <removeme/>.

In Tridion CM xml there is no difference between an empty node or none existing node, the CM will not remove the whole node.

  • 1
    There actually is a difference, but in most (if not all) cases SDL Tridion treats an empty node the same as a non existing element (basically an IsNullOrEmpty check). The UI will remove the element when it is empty in the XML on save, not sure if the same thing happens in the Core Service. But since SDL Tridion treats both conditions equally, it doesn't really matter indeed. – Bart Koopman Oct 31 '13 at 9:22
  • I looked for documentation on the partial update but cannot find anything. I have read about it, don't remember where. – Jan H Oct 31 '13 at 12:15
2

Not sure what you are after here at all? You want to remove a field then you do this from the schema to remove the field.

If you want to empty the field then set it to "".

Hope this helps.

  • Thanks for the response. I want to make that field empty. I also need to remove the xml tag from content xml. – Patan Oct 30 '13 at 16:52

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.