private static XMPNode followXPathStep(
				XMPNode parentNode, 
				XMPPathSegment nextStep,
				boolean createNodes) throws XMPException
	{
		XMPNode nextNode = null;
		int index = 0;
		int stepKind = nextStep.getKind();
		
		if (stepKind == XMPPath.STRUCT_FIELD_STEP)
		{
			nextNode = findChildNode(parentNode, nextStep.getName(), createNodes);
		}
		else if (stepKind == XMPPath.QUALIFIER_STEP)
		{
			nextNode = findQualifierNode(
				parentNode, nextStep.getName().substring(1), createNodes);
		}
		else
		{
			// This is an array indexing step. First get the index, then get the node.

			if (!parentNode.getOptions().isArray())
			{
				throw new XMPException("Indexing applied to non-array", XMPError.BADXPATH);
			}

			if (stepKind == XMPPath.ARRAY_INDEX_STEP)
			{
				index = findIndexedItem(parentNode, nextStep.getName(), createNodes);
			}
			else if (stepKind == XMPPath.ARRAY_LAST_STEP)
			{
				index = parentNode.getChildrenLength();
			}
			else if (stepKind == XMPPath.FIELD_SELECTOR_STEP)
			{
				String[] result = Utils.splitNameAndValue(nextStep.getName());
				String fieldName = result[0];
				String fieldValue = result[1];
				index = lookupFieldSelector(parentNode, fieldName, fieldValue);
			}
			else if (stepKind == XMPPath.QUAL_SELECTOR_STEP)
			{
				String[] result = Utils.splitNameAndValue(nextStep.getName());
				String qualName = result[0];
				String qualValue = result[1];
				index = lookupQualSelector(
					parentNode, qualName, qualValue, nextStep.getAliasForm());
			}
			else
			{
				throw new XMPException("Unknown array indexing step in FollowXPathStep",
						XMPError.INTERNALFAILURE);
			}

			if (1 <= index  &&  index <=  parentNode.getChildrenLength())
			{
				nextNode = parentNode.getChild(index);
			}
		}
	
		return nextNode;		
	}