private PrimitiveValue lookupValueRef(final Node node)
    {
        try
        {
            final int periodIndex = valueRef.indexOf('.');
            final String valueRefType = valueRef.substring(0, periodIndex);

            final XPath xPath = XPathFactory.newInstance().newXPath();
            final Node valueRefNode = (Node)xPath.compile(
                "/*[local-name() = 'messageSchema']/types/enum[@name='" + valueRefType + "']")
                .evaluate(node.getOwnerDocument(), XPathConstants.NODE);

            if (valueRefNode == null)
            {
                XmlSchemaParser.handleError(node, "valueRef not found: " + valueRefType);
                return null;
            }

            final EnumType enumType = new EnumType(valueRefNode);
            if (enumType.encodingType() != primitiveType)
            {
                handleError(node, "valueRef does not match this type: " + valueRef);
                return null;
            }

            final String validValueName = valueRef.substring(periodIndex + 1);
            final EnumType.ValidValue validValue = enumType.getValidValue(validValueName);

            if (null == validValue)
            {
                handleError(node, "valueRef for validValue name not found: " + validValueName);
                return null;
            }

            return validValue.primitiveValue();
        }
        catch (final XPathException ex)
        {
            throw new RuntimeException(ex);
        }
    }
Construct a new encodedDataType from XML Schema.

@param node           from the XML Schema Parsing.
@param givenName      for this node.
@param referencedName of the type when created from a ref in a composite.
sbe-tool/src/main/java/uk/co/real_logic/sbe/xml/EncodedDataType.java