@Override public String evaluate(OMElement message) throws JaxenException { String value = ""; OMElement element = (OMElement)xpathProcessor.selectSingleNode(message); if (element != null) { value = element.getText(); } return value; } }
private String hl7Time(OMElement rootEl) throws Exception { AXIOMXPath xpathEx = new AXIOMXPath("//TestResults//Time"); OMElement selectEl = (OMElement) xpathEx.selectSingleNode(rootEl); return selectEl.getText(); }
@Override public String evaluate(OMElement message) throws JaxenException { String value = ""; OMAttribute attribute = (OMAttribute)xpathProcessor.selectSingleNode(message); if (attribute != null) { value = attribute.getAttributeValue(); } return value; } }
private String site(OMElement rootEl) throws Exception { AXIOMXPath xpathEx = new AXIOMXPath("//TestResults//Site"); OMElement selectEl = (OMElement) xpathEx.selectSingleNode(rootEl); return selectEl.getText(); }
private boolean logStatus(OMElement rootEl) throws Exception { AXIOMXPath xpathEx = new AXIOMXPath("//TestResults"); OMElement selectEl = (OMElement) xpathEx.selectSingleNode(rootEl); String statusValue = selectEl.getAttributeValue(MetadataSupport.status_qname); return "Pass".equals(statusValue); }
public boolean match(Event<MessageContext> event) { MessageContext messageContext = event.getMessage(); String evaluatedValue = null; try { OMElement topicNode = (OMElement) sourceXpath.selectSingleNode( messageContext.getEnvelope()); if (topicNode != null) { evaluatedValue = topicNode.getText(); } } catch (JaxenException e) { handleException("Error creating topic xpath",e); } if (evaluatedValue != null){ if (evaluatedValue.equals(resultValue)) { return true; } else if (evaluatedValue.startsWith((resultValue + FILTER_SEP).trim())) { return true; } } return false; }
private static boolean validateRXTContent(String rxtContent, String xsdPath) throws RegistryException { try { OMElement rxt = getRXTContentOMElement(rxtContent); AXIOMXPath xpath = new AXIOMXPath("//artifactType"); OMElement c1 = (OMElement) xpath.selectSingleNode(rxt); InputStream is = new ByteArrayInputStream(c1.toString().getBytes()); Source xmlFile = new StreamSource(is); SchemaFactory schemaFactory = SchemaFactory .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(new File(xsdPath)); Validator validator = schema.newValidator(); validator.validate(xmlFile); } catch (Exception e) { log.error("RXT validation fails due to: " + e.getMessage()); return false; } return true; }
public boolean match(Event<MessageContext> event) { MessageContext messageContext = event.getMessage(); String evaluatedValue = null; try { OMElement topicNode = (OMElement) sourceXpath.selectSingleNode( messageContext.getEnvelope()); if (topicNode != null) { evaluatedValue = topicNode.getText(); } } catch (JaxenException e) { handleException("Error creating topic xpath",e); } if (evaluatedValue != null){ if (evaluatedValue.equals(resultValue)) { return true; } else if (evaluatedValue.startsWith((resultValue + FILTER_SEP).trim())) { return true; } } return false; }
/** * Digests the custom quote response and extracts the last trade price * @param result * @return * @throws javax.xml.stream.XMLStreamException * * <CheckPriceResponse xmlns="http://ws.invesbot.com/" > * <Code>IBM</Code> * <Price>82.90</Price> * </CheckPriceResponse> */ public static String parseCustomQuoteResponse(OMElement result) throws Exception { AXIOMXPath xPath = new AXIOMXPath("//ns:Price"); xPath.addNamespace("ns","http://services.samples/xsd"); OMElement price = (OMElement) xPath.selectSingleNode(result); if (price != null) { return price.getText(); } else { throw new Exception("Unexpected response : " + result); } }
import org.apache.axiom.om.OMElement; import org.apache.axiom.om.xpath.AXIOMXPath; import org.jaxen.JaxenException; public String hello(OMElement xmlElement) { try { AXIOMXPath someXPath = new AXIOMXPath("//root/child"); String str = ((OMElement)someXPath.selectSingleNode(node)).getText(); } catch (JaxenException e) { e.printStackTrace(); } }
/** * Digests the custom quote response and extracts the last trade price * @param result * @return * @throws javax.xml.stream.XMLStreamException * * <CheckPriceResponse xmlns="http://ws.invesbot.com/" > * <Code>IBM</Code> * <Price>82.90</Price> * </CheckPriceResponse> */ public static String parseCustomQuoteResponse(OMElement result) throws Exception { AXIOMXPath xPath = new AXIOMXPath("//ns:Price"); xPath.addNamespace("ns","http://services.samples/xsd"); OMElement price = (OMElement) xPath.selectSingleNode(result); if (price != null) { return price.getText(); } else { throw new Exception("Unexpected response : " + result); } }
/** * Digests the custom quote response and extracts the last trade price * @param result * @return * @throws javax.xml.stream.XMLStreamException * * <CheckPriceResponse xmlns="http://ws.invesbot.com/" > * <Code>IBM</Code> * <Price>82.90</Price> * </CheckPriceResponse> */ public static String parseCustomQuoteResponse(OMElement result) throws Exception { AXIOMXPath xPath = new AXIOMXPath("//ns:Price"); xPath.addNamespace("ns","http://services.samples/xsd"); OMElement price = (OMElement) xPath.selectSingleNode(result); if (price != null) { return price.getText(); } else { throw new Exception("Unexpected response : " + result); } }
public List<Subscription> getMatchingSubscriptions(Event<MessageContext> event) throws EventException { MessageContext mc = event.getMessage(); log.debug("Got SOAP Envelope: " + mc.getEnvelope()); String topic = null; try { OMElement topicNode = (OMElement) topicXPath.selectSingleNode(mc.getEnvelope()); if (topicNode != null) { topic = topicNode.getText(); } } catch (JaxenException e) { log.error("Topic not found"); throw new EventException("Topic not found", e); } event.setTopic(topic); return super.getMatchingSubscriptions(event); }
public List<Subscription> getMatchingSubscriptions(Event<MessageContext> event) throws EventException { MessageContext mc = event.getMessage(); log.debug("Got SOAP Envelope: " + mc.getEnvelope()); String topic = null; try { OMElement topicNode = (OMElement) topicXPath.selectSingleNode(mc.getEnvelope()); if (topicNode != null) { topic = topicNode.getText(); } } catch (JaxenException e) { log.error("Topic not found"); throw new EventException("Topic not found", e); } event.setTopic(topic); return super.getMatchingSubscriptions(event); }
private Pair <String, String> getClassCode(XMLAssertion a, OMElement stdElement2) throws Exception { OMElement cat = (OMElement) a.xPath.selectSingleNode(stdElement2); String nodeRepresentation = cat.getAttributeValue(new QName("nodeRepresentation")); OMElement slot = getChildElement(cat, "Slot", "name", "codingScheme"); OMElement valueList = getChildElement(slot, "ValueList"); OMElement value = getChildElement(valueList, "Value"); String codingScheme = value.getText().trim(); return new Pair <String, String>(nodeRepresentation, codingScheme); }
public synchronized Object getNode( OMElement context, XPath xpath ) throws XMLParsingException { Object node; try { node = getAXIOMXPath( xpath ).selectSingleNode( context ); } catch ( JaxenException e ) { throw new XMLParsingException( this, context, e.getMessage() ); } return node; }
public OMElement getSection(String sectionName) throws XdsInternalException { AXIOMXPath xpathExpression; try { xpathExpression = new AXIOMXPath("//*[local-name()='" + sectionName + "']"); List <OMElement> y = (List <OMElement>) xpathExpression.selectNodes(root); OMElement x = (OMElement) xpathExpression.selectSingleNode(root); return x; } catch (JaxenException e) { throw new XdsInternalException("Error extracting section " + sectionName + " from log output", e); } }
XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new StringBufferInputStream(responseXML)); OMElement documentElement = new StAXOMBuilder(parser).getDocumentElement(); AXIOMXPath oTA_HotelAvailRSXPath = new AXIOMXPath("/soap:Envelope/soap:Body/wmHotelAvailResponse/OTA_HotelAvailRS"); oTA_HotelAvailRSXPath.addNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/"); oTA_HotelAvailRSXPath.addNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); oTA_HotelAvailRSXPath.addNamespace("xsd", "http://www.w3.org/2001/XMLSchema"); OMElement oTA_HotelAvailRSOmElement = (OMElement)oTA_HotelAvailRSXPath.selectSingleNode(documentElement); OMElement errorsOmElement = (OMElement)new AXIOMXPath("Errors").selectSingleNode(oTA_HotelAvailRSOmElement); String strType = (String) new AXIOMXPath("string(Text/@Type)").selectSingleNode(errorsOmElement); String strCode = (String) new AXIOMXPath("string(Text/@Code)").selectSingleNode(errorsOmElement); String strDescription = (String) new AXIOMXPath("string(Text)").selectSingleNode(errorsOmElement);
public void testXPath() { try { OMElement element = AXIOMUtil.stringToOM(getXmlOfMediatorScenarioOneA("full")); AXIOMXPath xPath = new AXIOMXPath("//property/@name"); //xPath.addNamespace(SynapseConstants.SYNAPSE_NAMESPACE, ""); Object o = xPath.selectSingleNode(element); if (o instanceof OMAttribute) { System.out.println(((OMAttribute) o).getAttributeValue()); } } catch (XMLStreamException e) { e.printStackTrace(); } catch (JaxenException e) { e.printStackTrace(); } }
public void testXPathEvaluationOnRegistryResource() throws Exception { SimpleURLRegistry registry = new SimpleURLRegistry(); OMNode omNode = registry.lookup( "file:src/test/resources/org/apache/synapse/core/registry/resource.xml"); assertNotNull(omNode); AXIOMXPath xpath = new AXIOMXPath("//table/entry[@id='one']/value/child::text()"); OMNode node = (OMNode) xpath.selectSingleNode(omNode); assertNotNull(node); assertTrue(node instanceof OMText); assertEquals("ValueOne", ((OMText) node).getText()); }