/// <summary>
        /// Finds the item field.
        /// </summary>
        /// <param name="parts">The parts.</param>
        /// <param name="currentIndex">Index of the current.</param>
        /// <param name="fields">The fields.</param>
        /// <param name="isMultiValue">if set to <c>true</c> [is multi value].</param>
        /// <returns></returns>
        private ItemField FindItemField(string[] parts, int currentIndex, ItemFields fields, out bool isMultiValue)
        {
            string input = parts[currentIndex];
            int num = -1;
            Match match = PartRegex.Match(input);
            if (match.Success)
            {
                input = match.Groups[1].Value;
                num = Convert.ToInt32(match.Groups[3].Value);
            }
            if (fields.Contains(input))
            {
                ItemField field = fields[input];
                if ((parts.Length - 1) == currentIndex)
                {
                    isMultiValue = field.Definition.MaxOccurs != 1;
                    return field;
                }
                else
                {
                    if (field is EmbeddedSchemaField)
                    {
                        EmbeddedSchemaField schema = field as EmbeddedSchemaField;
                        if (schema != null)
                            return (FindItemField(parts, currentIndex + 1, ((num >= 0) ? (schema.Values[num]) : schema.Value), out isMultiValue));
                    }
                    else if (field is ComponentLinkField || field is MultimediaLinkField)
                    {
                        Component LinkedComponent = null;
                        if (field is ComponentLinkField)
                        {
                            ComponentLinkField componentLink = field as ComponentLinkField;
                            LinkedComponent = new Component(((num >= 0) ? (componentLink.Values[num].Id) : componentLink.Value.Id), _engine.GetSession());
                        }
                        else
                        {
                            MultimediaLinkField componentLink = field as MultimediaLinkField;
                            LinkedComponent = new Component(((num >= 0) ? (componentLink.Values[num].Id) : componentLink.Value.Id), _engine.GetSession());
                        }

                        FieldOutputHandler subHandler = new FieldOutputHandler(LinkedComponent.Id, _engine, _package);
                        subHandler.SiteEdit = false;
                        _disableSiteEdit = true;
                        subHandler.EscapeOutput = _escapeOutput;
                        subHandler.DateFormat = _dateFormat;
                        subHandler.Culture = _culture.ToString();
                        subHandler.PushBinariesToPackage = _pushBinariesToPackage;
                        String QualifiedFieldName = String.Empty;
                        for (int i = currentIndex + 1; i < parts.Length; i++)
                        {
                            QualifiedFieldName += parts[i];
                            if (i < (parts.Length - 1))
                                QualifiedFieldName += ".";
                        }
                        isMultiValue = field.Definition.MaxOccurs != 1;
                        if (_returnType == "ComponentLinkField")
                            return subHandler.GetComponentLinkField(QualifiedFieldName);
                        else if (_returnType == "EmbeddedSchemaField")
                            return subHandler.GetEmbeddedSchemaField(QualifiedFieldName);
                        else
                            return null;
                    }

                    Log.Warning(string.Format("Part \"{0}\" in qualified field name was expected to refer to an embedded schema!", field.Name));

                }
            }
            isMultiValue = false;
            return null;
        }
        /// <summary>
        /// Finds the item field X path and value.
        /// </summary>
        /// <param name="parts">The parts.</param>
        /// <param name="currentIndex">Index of the current.</param>
        /// <param name="currentXpath">The current xpath.</param>
        /// <param name="fields">The fields.</param>
        /// <param name="isMultiValue">if set to <c>true</c> [is multi value].</param>
        /// <returns>The field's value wrapped in SiteEdit span tags if SiteEdit is set to <c>true</c>.</returns>
        private string FindItemFieldXPathAndValue(string[] parts, int currentIndex, string currentXpath, ItemFields fields, out bool isMultiValue)
        {
            if (_itemType != ItemType.Component)
                _disableSiteEdit = true;

            string input = parts[currentIndex];
            int num = -1;
            Match match = PartRegex.Match(input);
            if (match.Success)
            {
                input = match.Groups[1].Value;
                num = Convert.ToInt32(match.Groups[3].Value);
            }
            if (fields != null)
            {
                if (fields.Contains(input))
                {
                    ItemField field = fields[input];
                    if ((parts.Length - 1) == currentIndex)
                    {
                        isMultiValue = field.Definition.MaxOccurs != 1;
                        string fieldValue = GetFieldValue(field, ((num == -1) ? 0 : num));
                        if (_siteEdit && !_disableSiteEdit)
                            if (_siteEditVersion == SiteEditVersion.SiteEdit13)
                                return (String.Format(_siteEditFormatString, ((_isContent) ? "Content" : "Metadata"), (((_isContent) ? _component.Content.LocalName : _component.Metadata.LocalName) + "/" + currentXpath) + "custom:" + field.Name + ((num >= 0) ? ("[" + (num + 1) + "]") : ""), fieldValue));
                            else
                                return (String.Format(SiteEdit2009FormatString, ((_isContent) ? "Fields" : "MetaData") + "." + currentXpath + field.Name, ((num >= 0) ? num : 0), fieldValue));
                        else
                            return fieldValue;
                    }
                    EmbeddedSchemaField schema = field as EmbeddedSchemaField;
                    if (schema != null && schema is EmbeddedSchemaField)
                    {
                        return (this.FindItemFieldXPathAndValue(parts, currentIndex + 1, currentXpath + "custom:" + field.Name + ((num >= 0) ? ("[" + (num + 1) + "]") : "") + "/", ((num >= 0) ? (schema.Values[num]) : schema.Value), out isMultiValue));
                    }
                    else if (field is ComponentLinkField || field is MultimediaLinkField)
                    {
                        Component LinkedComponent = null;
                        if (field is ComponentLinkField)
                        {
                            ComponentLinkField componentLink = field as ComponentLinkField;
                            LinkedComponent = new Component(((num >= 0) ? (componentLink.Values[num].Id) : componentLink.Value.Id), _engine.GetSession());
                        }
                        else
                        {
                            MultimediaLinkField componentLink = field as MultimediaLinkField;
                            LinkedComponent = new Component(((num >= 0) ? (componentLink.Values[num].Id) : componentLink.Value.Id), _engine.GetSession());
                        }

                        FieldOutputHandler subHandler = new FieldOutputHandler(LinkedComponent.Id, _engine, _package);
                        subHandler.SiteEdit = false;
                        _disableSiteEdit = true;
                        subHandler.EscapeOutput = _escapeOutput;
                        subHandler.DateFormat = _dateFormat;
                        subHandler.Culture = _culture.ToString();
                        subHandler.PushBinariesToPackage = _pushBinariesToPackage;
                        String QualifiedFieldName = String.Empty;
                        for (int i = currentIndex + 1; i < parts.Length; i++)
                        {
                            QualifiedFieldName += parts[i];
                            if (i < (parts.Length - 1))
                                QualifiedFieldName += ".";
                        }
                        isMultiValue = field.Definition.MaxOccurs != 1;
                        String SubHandlerResult = subHandler.GetStringValue(QualifiedFieldName);
                        return SubHandlerResult;
                    }
                    else if (field is KeywordField)
                    {
                        KeywordField Keyfield = (KeywordField)field;
                        FieldOutputHandler subHandler = new FieldOutputHandler(Keyfield.Values[0].Id, _engine, _package);
                        subHandler.SiteEdit = false;
                        _disableSiteEdit = true;
                        subHandler.EscapeOutput = _escapeOutput;
                        subHandler.DateFormat = _dateFormat;
                        subHandler.Culture = _culture.ToString();
                        subHandler.PushBinariesToPackage = _pushBinariesToPackage;
                        String QualifiedFieldName = String.Empty;
                        for (int i = currentIndex + 1; i < parts.Length; i++)
                        {
                            QualifiedFieldName += parts[i];
                            if (i < (parts.Length - 1))
                                QualifiedFieldName += ".";
                        }
                        isMultiValue = field.Definition.MaxOccurs != 1;
                        String SubHandlerResult = subHandler.GetStringValue(QualifiedFieldName);
                        return SubHandlerResult;

                    }

                    Log.Warning(string.Format("Part {0} in qualified field name was expected to refer to an embedded schema!", field.Name));
                }
            }
            isMultiValue = false;
            return null;
        }