/// <summary>
        /// Stores the element in an extension.
        /// </summary>
        /// <param name="extensible">The object that is being extended.</param>
        /// <param name="element">The element to store.</param>
        /// <returns>This method always returns true.</returns>
        public bool StoreElement(IExtensible extensible, ElementInfo element)
        {
            TestExtension extension;

            extension = extensible.Extensions.FirstOrDefault((e) => e.Name == TestExtension.ExtensionName) as TestExtension;
            if (extension == null)
            {
                extension = new TestExtension();
                extensible.Extensions.Add(extension);
            }

            extension.AddChild(element);

            return true;
        }
        /// <summary>
        /// Demonstrates how to store custom attributes and elements on a <see cref="File"/> element using the built in
        /// generic extension support.
        /// </summary>
        public static void StoreGenericExtension()
        {
            IExtensible extensible;
            GenericExtension extension;
            File file;

            // This namespace will be stored on the document element like: <xliff xmlns:pre1="urn:custom:extension:1.0"
            const string customNamespace = "urn:custom:extension:1.0";
            const string customPrefix = "pre1";

            file = new File("f1");
            extensible = file;
            extension = new GenericExtension("custom");

            // Create custom attributes that look like: <file id="f1" pre1:attr1="value1" pre1:attr2="value2">
            if (extensible.SupportsAttributeExtensions)
            {
                extension.AddAttribute(new GenericExtensionAttribute(customPrefix, customNamespace, "attr1", "value1"));
                extension.AddAttribute(new GenericExtensionAttribute(customPrefix, customNamespace, "attr2", "value2"));
                extensible.Extensions.Add(extension);
            }

            // Create a custom element that looks like: <pre1:element1 pre1:attr1="value1" />
            if (extensible.SupportsElementExtensions)
            {
                ElementInfo info;
                GenericElement element;

                element = new GenericElement();
                element.SetAttribute(customPrefix, customNamespace, "attr1", "value1");
                info = new ElementInfo(new XmlNameInfo(customPrefix, customNamespace, "element1"), element);
                extension.AddChild(info);
            }
        }
        /// <summary>
        /// Demonstrates how to store custom attributes and elements on a <see cref="File"/> element using a custom
        /// extension and element types.
        /// </summary>
        public static void StoreCustomExtension()
        {
            TestExtension extension;
            IExtensible extensible;
            Segment segment;
            XliffDocument document;
            XliffReader reader;
            Unit unit;
            string path;

            // This namespace will be stored on the document element like: <xliff xmlns:pre1="urn:custom:extension:1.0"
            const string customNamespace = "urn:custom:extension:1.0";
            const string customPrefix = "customPrefix";

            extension = new TestExtension();

            document = new XliffDocument("en-us");
            document.Files.Add(new File("f1"));

            unit = new Unit("u1");
            document.Files[0].Containers.Add(unit);

            segment = new Segment("s1");
            unit.Resources.Add(segment);

            segment.Source = new Source();
            segment.Source.Text.Add(new PlainText("text"));

            extensible = document.Files[0];

            // Create custom attributes that look like: <file id="f1" pre1:testattr1="testvalue1" pre1:testattr2="testvalue2">
            if (extensible.SupportsAttributeExtensions)
            {
                extension.AddAttribute(new TestAttribute(customPrefix, customNamespace, "testattr1", "testvalue1"));
                extension.AddAttribute(new TestAttribute(customPrefix, customNamespace, "testattr2", "testvalue2"));
                extensible.Extensions.Add(extension);
            }

            // Create a custom element that looks like: <pre1:testelement1 pre1:testattr1="testvalue1" />
            if (extensible.SupportsElementExtensions)
            {
                ElementInfo info;
                TestElement element;

                element = new TestElement();
                element.SetAttribute(customPrefix, customNamespace, "testattr1", "testvalue1");
                info = new ElementInfo(new XmlNameInfo(customPrefix, customNamespace, "testelement1"), element);
                extension.AddChild(info);
            }

            // Write the file just like any other file.
            path = IO.Path.GetTempFileName();
            SampleCode.WriteDocument(document, path);

            // Read the file using an custom extension handler so the custom types are loaded. The loaded File will
            // have the custom extension and attributes and elements on it just like it was created above.
            reader = new XliffReader();
            reader.RegisterExtensionHandler(customNamespace, new TestExtensionHandler());
            using (IO.FileStream stream = new IO.FileStream(path, IO.FileMode.Open, IO.FileAccess.Read))
            {
                document = reader.Deserialize(stream);
            }
        }
 /// <summary>
 /// Adds an element or text member to the extension data.
 /// </summary>
 /// <param name="child">The child to add.</param>
 public void AddChild(ElementInfo child)
 {
     this.children.Add(child);
 }
        /// <summary>
        /// Adds an element to this object as a child.
        /// </summary>
        /// <param name="element">The object to add.</param>
        public void AddChild(ElementInfo element)
        {
            ArgValidator.Create(element, "element").IsNotNull();

            this.StoreChild(element);
        }
        /// <summary>
        /// Stores the <see cref="XliffElement"/> as a child of this <see cref="XliffElement"/>.
        /// </summary>
        /// <param name="info">The object to add.</param>
        /// <returns>True if the child was stored, otherwise false.</returns>
        protected override bool StoreChild(ElementInfo info)
        {
            ArgValidator.ParentIsNull(info.Element);
            Utilities.SetParent(info.Element, this);

            if (info.Namespace == null)
            {
                XmlNameInfo name;

                name = new XmlNameInfo(info.Prefix, NamespaceValues.Core, info.LocalName);
                info = new ElementInfo(name, info.Element);
            }

            this.children.Value.Add(info);

            return true;
        }