// Bits for XPathStepInfo options. // /// <summary>Append a path segment</summary> /// <param name="segment">the segment to add</param> public void Add(XmpPathSegment segment) { _segments.Add(segment); }
/// <summary> /// After processing by ExpandXPath, a step can be of these forms: /// </summary> /// <remarks> /// After processing by ExpandXPath, a step can be of these forms: /// <list type="bullet"> /// <item>qualName - A top level property or struct field.</item> /// <item>[index] - An element of an array.</item> /// <item>[last()] - The last element of an array.</item> /// <item>[qualName="value"] - An element in an array of structs, chosen by a field value.</item> /// <item>[?qualName="value"] - An element in an array, chosen by a qualifier value.</item> /// <item>?qualName - A general qualifier.</item> /// </list> /// Find the appropriate child node, resolving aliases, and optionally creating nodes. /// </remarks> /// <param name="parentNode">the node to start to start from</param> /// <param name="nextStep">the xpath segment</param> /// <param name="createNodes"></param> /// <returns>returns the found or created XMPPath node</returns> /// <exception cref="XmpException"></exception> private static XmpNode FollowXPathStep(XmpNode parentNode, XmpPathSegment nextStep, bool createNodes) { XmpNode nextNode = null; var stepKind = nextStep.Kind; if (stepKind == XmpPath.StructFieldStep) { nextNode = FindChildNode(parentNode, nextStep.Name, createNodes); } else { if (stepKind == XmpPath.QualifierStep) { nextNode = FindQualifierNode(parentNode, nextStep.Name.Substring (1), createNodes); } else { // This is an array indexing step. First get the index, then get the node. if (!parentNode.Options.IsArray) { throw new XmpException("Indexing applied to non-array", XmpErrorCode.BadXPath); } var index = 0; if (stepKind == XmpPath.ArrayIndexStep) { index = FindIndexedItem(parentNode, nextStep.Name, createNodes); } else { if (stepKind == XmpPath.ArrayLastStep) { index = parentNode.GetChildrenLength(); } else { if (stepKind == XmpPath.FieldSelectorStep) { var result = Utils.SplitNameAndValue(nextStep.Name); var fieldName = result[0]; var fieldValue = result[1]; index = LookupFieldSelector(parentNode, fieldName, fieldValue); } else { if (stepKind == XmpPath.QualSelectorStep) { var result = Utils.SplitNameAndValue(nextStep.Name); var qualName = result[0]; var qualValue = result[1]; index = LookupQualSelector(parentNode, qualName, qualValue, nextStep.AliasForm); } else { throw new XmpException("Unknown array indexing step in FollowXPathStep", XmpErrorCode.InternalFailure); } } } } if (1 <= index && index <= parentNode.GetChildrenLength()) { nextNode = parentNode.GetChild(index); } } } return nextNode; }