Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:38:16+00:00 2026-06-01T17:38:16+00:00

I am updating a Component using Core Service in Tridion 2011. The sample code

  • 0

I am updating a Component using Core Service in Tridion 2011.

The sample code is as follows,

string COMPONENT_URI = "tcm:8-674";
string SCHEMA_URI = "tcm:8-426-8";

ComponentData component = client.TryCheckOut(COMPONENT_URI, null) as ComponentData;

try
{
    Response.Write("<BR>" + component.Content);
    XDocument xdoc = XDocument.Parse(component.Content);
    var element = xdoc.Elements("first").Single();
    element.Value = "updated";
    xdoc.Save(component.Content);
    client.Save(component, null);
    Response.Write("<BR"+"SAVED");
}
catch (Exception ex)
{
    Response.Write("Unable to save comp" + ex.Message);
}

client.CheckIn(COMPONENT_URI, null);

I am getting following exception:

 Unable to save compSequence contains no elements 

Details:

first – name of the field in the component

Can any one help regarding this?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:38:17+00:00Added an answer on June 1, 2026 at 5:38 pm

    The XML of a Component in Tridion is of the following format:

    <Content xmlns="uuid:2607D20D-1B22-4994-98C1-66D9ACF85C20">
      <first>The value of my first field</first>
      <second>The value of my second field</second>
    </Content>
    

    Your relevant code snippet is:

    var element = xdoc.Elements("first").Single();
    

    This is failing to select an element, since it is:

    1. not providing a namespace to the selection
    2. only selecting direct children of the document root

    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.

    If you modify the code to deal with these two issues, it should look something like this:

    XNamespace ns = xdoc.Root.GetDefaultNamespace();
    var element = xdoc.Descendants(ns+"first").Single();
    

    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.

    People who have wanted to update the Component XML through the Core Service before you found the helper class given here useful.

    In addition as Mihai points out the way you invoke XDocument.Save is wrong. It expects a file name as its parameter, while you are passing it the XML of your Component.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After updating to Parsec 3.1 from 2.x, code using many1, such as word =
I am updating a component via AJAX in JSF: <h:form> <h:outputLink>Click me <f:ajax event=click
After updating to XCode 4.3, all my archives built using XCode 4.2 are gone.
For updating in my .properties file I am using Apache Commons Configuration's PropertiesConfiguration .
I am updating various swing components using the event dispatching thread. However when I
I am using the WPF DataGrid component from the .NET 4 framework, it is
I'm fairly new to CakePHPand am building a site using the Auth component. A
I have a question about updating variable inside dataTable component, which was sended to
Updating an old piece of software but in order to maintain backward compatibility I
After updating to php 5.3 one of our systems has developed an interesting bug.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.