List of usage examples for org.w3c.dom Text getNodeValue
public String getNodeValue() throws DOMException;
From source file:org.apache.axis.message.MessageElement.java
/** * Get the value of the doc as a string. * This uses {@link #getAsDOM()} so is a heavyweight operation. * @return the value of any child node, or null if there is no node/something went * wrong during serialization. If the first child is text, the return value * is the text itself./*from w w w . j a v a 2 s . c o m*/ * @see javax.xml.soap.Node#getValue() ; */ public String getValue() { /*--- Fix for AXIS-1817 if ((recorder != null) && (!_isDirty)) { StringWriter writer = new StringWriter(); TextSerializationContext outputContext = new TextSerializationContext(writer); try { recorder.replay(startEventIndex, endEventIndex, new SAXOutputter(outputContext)); } catch (Exception t) { log.debug("getValue()", t); return null; } String value = writer.toString(); return (value.length() == 0) ? null : value; } ---*/ if (textRep != null) { // weird case: error? return textRep.getNodeValue(); } if (objectValue != null) { return getValueDOM(); } for (Iterator i = getChildElements(); i.hasNext();) { org.apache.axis.message.NodeImpl n = (org.apache.axis.message.NodeImpl) i.next(); if (n instanceof org.apache.axis.message.Text) { org.apache.axis.message.Text textNode = (org.apache.axis.message.Text) n; return textNode.getNodeValue(); } } return null; }
From source file:org.apache.camel.component.cxf.CxfConsumerPayloadXPathClientServerTest.java
@Override protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override/* www . j a v a 2s.c o m*/ public void configure() { from(simpleEndpointURI + "&dataFormat=PAYLOAD").to("log:info").process(new Processor() { @SuppressWarnings("unchecked") @Override public void process(final Exchange exchange) throws Exception { Object request = exchange.getIn().getBody(); assertIsInstanceOf(CxfPayload.class, request); //attempt 1) applying XPath to exchange.getIn().getBody() receivedMessageCxfPayloadApplyingXPath = XPathBuilder.xpath("//*[name()='arg0']/text()") .evaluate(context, request, String.class); //attempt 2) in stead of XPATH, browse the DOM-tree CxfPayload<SoapHeader> payload = (CxfPayload<SoapHeader>) request; Element el = payload.getBody().get(0); Element el2 = (Element) el.getFirstChild(); Text textnode = (Text) el2.getFirstChild(); receivedMessageByDom = textnode.getNodeValue(); textnode = (Text) textnode.getNextSibling(); while (textnode != null) { //the textnode appears to have siblings! receivedMessageByDom = receivedMessageByDom + textnode.getNodeValue(); textnode = (Text) textnode.getNextSibling(); } //attempt 3) apply XPATH after converting CxfPayload to String request = exchange.getIn().getBody(String.class); assertIsInstanceOf(String.class, request); receivedMessageStringApplyingXPath = XPathBuilder.xpath("//*[name()='arg0']/text()") .evaluate(context, request, String.class); //build some dummy response XmlConverter converter = new XmlConverter(); Document outDocument = converter.toDOMDocument(ECHO_RESPONSE); List<Source> outElements = new ArrayList<Source>(); outElements.add(new DOMSource(outDocument.getDocumentElement())); // set the payload header with null CxfPayload<SoapHeader> responsePayload = new CxfPayload<SoapHeader>(null, outElements, null); exchange.getOut().setBody(responsePayload); } }); } }; }
From source file:org.apache.uima.tools.docanalyzer.DBAnnotationViewerDialog.java
/** * Assumes node has a text field and extracts its value. JMP */// w w w . ja v a 2s . c om static public String getTextValue(Node node) { Node first = node.getFirstChild(); if (first != null) { Text text = (Text) node.getFirstChild(); return text.getNodeValue().trim(); } else return null; }
From source file:org.eclipse.uomo.xml.test.XMLTestCase.java
private String compareTexts(Text c1, Text c2, String p) { String s1 = normaliseWhitespace(c1.getNodeValue()); String s2 = normaliseWhitespace(c2.getNodeValue()); if (s1 == null && s2 == null) return null; else if (s1 == null || s2 == null || !s1.equals(s2)) return "Text differs @ " + p + ": '" + s1 + "' / '" + s2 + "'"; else/*ww w .j ava 2s . c o m*/ return null; }
From source file:util.XmlWriter.java
private void writeText(Text text) throws IOException { String nodeValue = text.getNodeValue(); write(nodeValue.trim()); }