public static String getCharacterDataFromElement(Element e) {
   for (int i = 0; i < e.getChildNodes().getLength(); i++) {
     Node child = e.getChildNodes().item(i);
     if (child instanceof CharacterData) {
       CharacterData cd = (CharacterData) child;
       String result = cd.getData().replaceAll(" ", "");
       result = result.replaceAll("\n", "");
       if (!result.equals("")) {
         return cd.getData();
       }
     }
   }
   return "";
 }
  // XMLToStringConverter
  private static String returnResultFromXML(String convertDocToString)
      throws SAXException, IOException, ParserConfigurationException {
    String alchemyResult = null;
    // XML Conversion
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    // Load the input XML document, parse it and return an instance of the
    // Document class.
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(convertDocToString));
    Document document = builder.parse(is);
    NodeList nodes = document.getElementsByTagName("results");
    for (int i = 0; i < nodes.getLength(); i++) {
      Element element = (Element) nodes.item(i);
      NodeList authorElement = element.getElementsByTagName("author");
      Element line = (Element) authorElement.item(i);
      // System.out.println("author is" + authorElement.toString());
      Node child = line.getFirstChild();
      if (child instanceof CharacterData) {
        CharacterData cd = (CharacterData) child;
        alchemyResult = cd.getData();
      }
    }

    return alchemyResult;
  }
Exemple #3
0
 /**
  * Gets the character data from element.
  *
  * @param e the e
  * @return the character data from element
  */
 public static String getCharacterDataFromElement(Element e) {
   Node child = e.getFirstChild();
   if (child instanceof CharacterData) {
     CharacterData cd = (CharacterData) child;
     return cd.getData();
   }
   return "";
 }
Exemple #4
0
 private String getCharacterDataFromElement(Element e) {
   try {
     Node child = e.getFirstChild();
     if (child instanceof CharacterData) {
       CharacterData cd = (CharacterData) child;
       return cd.getData();
     }
   } catch (Exception ignored) {
   }
   return "";
 }
 public static List<String> getStringFromElement(Element e) {
   NodeList childList = e.getChildNodes();
   ArrayList<String> elementValues = new ArrayList<String>();
   for (int i = 0; i < childList.getLength(); i++) {
     Node noodi = childList.item(i);
     if (noodi instanceof CharacterData) {
       CharacterData cd = (CharacterData) noodi;
       elementValues.add(cd.getData());
     }
   }
   return elementValues;
 }
  /**
   * Returns value/cdata from xml node.
   *
   * @param node
   * @return String
   */
  public static String getNodeValue(Node node) {

    String value = node.getNodeValue();
    if (value == null) {
      Node nChild = node.getFirstChild();
      if (nChild instanceof CharacterData) {
        CharacterData cd = (CharacterData) nChild;
        value = cd.getData();
      }
    }
    return value;
  }
  public void setDefaultDataModel(Object dataModel) {
    if (markupDrivenUtil != null) {
      HTMLTextAreaElement elem = getHTMLTextAreaElement();
      CharacterData text = (CharacterData) elem.getFirstChild();
      String data;
      if (text != null) data = text.getData();
      else data = "";
      DOMUtilInternal.setAttribute(elem, "value", data);
    }

    if (markupDrivenUtil != null) markupDrivenUtil.preSetDefaultDataModel(dataModel);

    super.setDefaultDataModel(dataModel);
  }
 /**
  * Runs the test case.
  *
  * @throws Throwable Any uncaught exception causes test to fail
  */
 public void runTest() throws Throwable {
   Document doc;
   NodeList elementList;
   Node nameNode;
   CharacterData child;
   String childData;
   doc = (Document) load("staff", true);
   elementList = doc.getElementsByTagName("address");
   nameNode = elementList.item(0);
   child = (CharacterData) nameNode.getFirstChild();
   child.deleteData(0, 16);
   childData = child.getData();
   assertEquals("characterdataDeleteDataBeginingAssert", "Dallas, Texas 98551", childData);
 }
  public void handleEvent(Event evt) {
    super.handleEvent(evt);

    ItsNatHTMLSelectMultImpl comp = getItsNatHTMLSelectMult();
    //        if (comp.isServerUpdatingFromClient())
    //            return;

    String type = evt.getType();
    if (type.equals("DOMCharacterDataModified")) {
      MutationEvent mutEvent = (MutationEvent) evt;
      CharacterData charDataNode = (CharacterData) mutEvent.getTarget();
      HTMLOptionElement option = (HTMLOptionElement) charDataNode.getParentNode();
      int index = option.getIndex();
      String value = charDataNode.getData();
      DefaultListModel dataModel = (DefaultListModel) comp.getListModel();
      if (!value.equals(dataModel.get(index))) dataModel.set(index, value);
    }
  }