Java Code Examples for org.w3c.dom.Text#getNodeValue()
The following examples show how to use
org.w3c.dom.Text#getNodeValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrackWriterTest.java From mytracks with Apache License 2.0 | 6 votes |
/** * Gets the text data contained inside a tag. * * @param parent the parent of the tag containing the text * @param elementName the name of the tag containing the text * @return the text contents */ protected String getChildTextValue(Element parent, String elementName) { Element child = getChildElement(parent, elementName); assertTrue(child.hasChildNodes()); NodeList children = child.getChildNodes(); int length = children.getLength(); assertTrue(length > 0); // The children may be a sucession of text elements, just concatenate them String result = ""; for (int i = 0; i < length; i++) { Text textNode = (Text) children.item(i); result += textNode.getNodeValue(); } return result; }
Example 2
Source File: XMLUtil.java From netbeans with Apache License 2.0 | 5 votes |
/** * Extract nested text from an element. * Currently does not handle coalescing text nodes, CDATA sections, etc. * @param parent a parent element * @return the nested text, or null if none was found */ static String findText(Element parent) { NodeList l = parent.getChildNodes(); for (int i = 0; i < l.getLength(); i++) { if (l.item(i).getNodeType() == Node.TEXT_NODE) { Text text = (Text)l.item(i); return text.getNodeValue(); } } return null; }
Example 3
Source File: XMLUtil.java From netbeans with Apache License 2.0 | 5 votes |
/** * Extract nested text from a node. * Currently does not handle coalescing text nodes, CDATA sections, etc. * @param parent a parent element * @return the nested text, or null if none was found * * @since 8.4 */ public static String findText(Node parent) { NodeList l = parent.getChildNodes(); for (int i = 0; i < l.getLength(); i++) { if (l.item(i).getNodeType() == Node.TEXT_NODE) { Text text = (Text) l.item(i); return text.getNodeValue(); } } return null; }
Example 4
Source File: AppEngineXsltTransformTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testAddRuntimeAtEnd() { Document transformed = transform("/xslt/addJava8Runtime.xsl", "<appengine-web-app xmlns=\"http://appengine.google.com/ns/1.0\"><threadsafe>true</threadsafe></appengine-web-app>"); Element runtime = getRuntimeElement(transformed); assertEquals("java8", runtime.getTextContent()); Text previous = (Text) runtime.getPreviousSibling(); assertTrue(previous.getNodeValue().trim().isEmpty()); Text next = (Text) runtime.getNextSibling(); String s = next.getNodeValue(); assertEquals("\n", s); }
Example 5
Source File: test_AbstractNodeTester.java From xmlunit with Apache License 2.0 | 5 votes |
public void testText(Text text) { String fullText = text.getNodeValue(); if (fullText.startsWith("bar")) { Assert.assertFalse("testText called", textCalled); } if (!"barhelloxyzzy".equals(fullText)) { if (!textCalled) { Assert.assertEquals("bar", fullText); } else { Assert.assertEquals("helloxyzzy", fullText); } } // else - parser didn't expand entity reference textCalled = true; }
Example 6
Source File: GatewayResponse.java From scipio-erp with Apache License 2.0 | 4 votes |
/** * Creates the GatewayResponse object by parsing an xml from a stream. Fills in * the fields of the object that are available through getters after this method * returns. * * @param xmlstream * the stream to parse the response from * @throws Exception * if the xml contains a root element with a bad name or an unknown * element, or if the xml is badly formatted */ public GatewayResponse(InputStream xmlstream, GatewayRequest req) throws Exception { DocumentBuilderFactory builderFactory = DocumentBuilderFactory .newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document doc = builder.parse(xmlstream); // get the root node Node rootnode = doc.getDocumentElement(); String root = rootnode.getNodeName(); //if (root != "ewayResponse") { // SCIPIO: bad if (!"ewayResponse".equals(root)) { throw new Exception("Bad root element in response: " + root); } // get all elements NodeList list = doc.getElementsByTagName("*"); int length = list.getLength(); for (int i = 0; i < length; i++) { Node node = list.item(i); String name = node.getNodeName(); //if (name == "ewayResponse") { // SCIPIO: bad if ("ewayResponse".equals(name)) { continue; } Text textnode = (Text) node.getFirstChild(); String value = ""; if (textnode != null) { value = textnode.getNodeValue(); } // SCIPIO: 2018-09-26: Added break statements missing from upstream switch(name) { case "ewayTrxnError": txTrxnError = value; break; case "ewayTrxnStatus": if ("true".equals(value.toLowerCase(Locale.getDefault()).trim())) { txTrxnStatus = true; } break; case "ewayTrxnNumber": txTrxnNumber = value; break; case "ewayTrxnOption1": txTrxnOption1 = value; break; case "ewayTrxnOption2": txTrxnOption2 = value; break; case "ewayTrxnOption3": txTrxnOption3 = value; break; case "ewayReturnAmount": if (!value.equals("")) { txReturnAmount = Integer.parseInt(value); } break; case "ewayAuthCode": txAuthCode = value; break; case "ewayTrxnReference": txTrxnReference = value; break; case "ewayBeagleScore": if (!value.equals("")) { txBeagleScore = Double.parseDouble(value); } break; default: throw new Exception("Unknown field in response: " + name); } } if (req.isTestMode()) { Debug.logInfo("[eWay Reply]\n" + this.toString(), module); } }
Example 7
Source File: XMLParsing.java From webstart with MIT License | 4 votes |
public static XMLNode convert( Node n ) { if ( n == null ) { return null; } else if ( n instanceof Text ) { Text tn = (Text) n; return new XMLNode( tn.getNodeValue() ); } else if ( n instanceof Element ) { Element en = (Element) n; XMLAttribute xmlatts = null; NamedNodeMap attributes = en.getAttributes(); for ( int i = attributes.getLength() - 1; i >= 0; i-- ) { Attr ar = (Attr) attributes.item( i ); xmlatts = new XMLAttribute( ar.getName(), ar.getValue(), xmlatts ); } // Convert childern XMLNode thisNode = new XMLNode( en.getNodeName(), xmlatts, null, null ); ; XMLNode last = null; Node nn = en.getFirstChild(); while ( nn != null ) { if ( thisNode.getNested() == null ) { last = convert( nn ); thisNode.setNested( last ); } else { XMLNode nnode = convert( nn ); last.setNext( nnode ); last = nnode; } last.setParent( thisNode ); nn = nn.getNextSibling(); } return thisNode; } return null; }