Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The XML of a Component in Tridion is of the following format:</p> <pre><code>&lt;Content xmlns="uuid:2607D20D-1B22-4994-98C1-66D9ACF85C20"&gt; &lt;first&gt;The value of my first field&lt;/first&gt; &lt;second&gt;The value of my second field&lt;/second&gt; &lt;/Content&gt; </code></pre> <p>Your relevant code snippet is:</p> <pre><code>var element = xdoc.Elements("first").Single(); </code></pre> <p>This is failing to select an element, since it is:</p> <ol> <li>not providing a namespace to the selection</li> <li>only selecting direct children of the document root</li> </ol> <p>You seem to expect that the default namespace will be automatically selected if you don't specify a namespace, which simply is not true. As soon as you have XML that deals with namespaces, every query will have to specify the correct namespace. </p> <p>If you modify the code to deal with these two issues, it should look something like this:</p> <pre><code>XNamespace ns = xdoc.Root.GetDefaultNamespace(); var element = xdoc.Descendants(ns+"first").Single(); </code></pre> <p>You might want to consider reading up on .NET handling of namespaces in XML and on XML namespaces in general, since this is a very common mistake that you simply need to get out of your system quickly.</p> <p>People who have wanted to update the Component XML through the Core Service before you found the helper class given <a href="http://code.google.com/p/tridion-practice/wiki/ChangeContentOrMetadata" rel="noreferrer">here</a> useful.</p> <p>In addition as Mihai points out the way you invoke <code>XDocument.Save</code> is wrong. It expects a file name as its parameter, while you are passing it the XML of your Component.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload