use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.
the class TestXPath20 method testProcessSimpleXpath.
public void testProcessSimpleXpath() throws Exception {
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = "/employees/employee[1]/location";
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
ElementType result = (ElementType) rs.first();
String resultValue = result.node_value().getTextContent();
assertEquals("Unexpected value returned", "Boston", resultValue);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.
the class TestXPath20 method testProcessSimpleXpathVariable.
public void testProcessSimpleXpathVariable() throws Exception {
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = "$input-context/employees/employee[1]/location";
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
ElementType result = (ElementType) rs.first();
String resultValue = result.node_value().getTextContent();
assertEquals("Unexpected value returned", "Boston", resultValue);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.
the class FnInScopePrefixes method lookupPrefixes.
private static List lookupPrefixes(ElementType element) {
Element domElm = (Element) element.node_value();
List prefixList = new ArrayList();
Node node = domElm;
while (node != null && node.getNodeType() != Node.DOCUMENT_NODE) {
NamedNodeMap attrs = node.getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
Node attr = attrs.item(i);
String prefix = null;
if (attr.getNamespaceURI() != null && attr.getNamespaceURI().equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
// Default Namespace
if (attr.getNodeName().equals(XMLConstants.XMLNS_ATTRIBUTE)) {
prefix = "";
} else {
// Should we check the namespace in the Dynamic Context and return that???
prefix = attr.getLocalName();
}
if (prefix != null) {
if (!prefixList.contains(prefix)) {
prefixList.add(prefix);
}
}
}
}
node = node.getParentNode();
}
return prefixList;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.
the class FnInScopePrefixes method expected_args.
/**
* Obtain a list of expected arguments.
*
* @return Result of operation.
*/
public static synchronized Collection expected_args() {
if (_expected_args == null) {
_expected_args = new ArrayList();
SeqType arg = new SeqType(new ElementType(), SeqType.OCC_PLUS);
_expected_args.add(arg);
}
return _expected_args;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType in project webtools.sourceediting by eclipse.
the class FnIDREF method idref.
/**
* Insert-Before operation.
*
* @param args
* Result from the expressions evaluation.
* @param dc
* @throws DynamicError
* Dynamic error.
* @return Result of fn:insert-before operation.
*/
public static ResultSequence idref(Collection args, EvaluationContext ec) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultBuffer rs = new ResultBuffer();
Iterator argIt = cargs.iterator();
ResultSequence idrefRS = (ResultSequence) argIt.next();
String[] idst = idrefRS.first().getStringValue().split(" ");
ArrayList ids = createIDs(idst);
ResultSequence nodeArg = null;
NodeType nodeType = null;
if (argIt.hasNext()) {
nodeArg = (ResultSequence) argIt.next();
nodeType = (NodeType) nodeArg.first();
} else {
if (ec.getContextItem() == null) {
throw DynamicError.contextUndefined();
}
if (!(ec.getContextItem() instanceof NodeType)) {
throw new DynamicError(TypeError.invalid_type(null));
}
nodeType = (NodeType) ec.getContextItem();
if (nodeType.node_value().getOwnerDocument() == null) {
throw DynamicError.contextUndefined();
}
}
Node node = nodeType.node_value();
if (node.getOwnerDocument() == null) {
// W3C test suite seems to want XPDY0002 here
throw DynamicError.contextUndefined();
// throw DynamicError.noContextDoc();
}
if (hasID(ids, node)) {
ElementType element = new ElementType((Element) node, ec.getStaticContext().getTypeModel());
rs.add(element);
}
rs = processAttributes(node, ids, rs, ec);
rs = processChildNodes(node, ids, rs, ec);
return rs.getSequence();
}
Aggregations