Example usage for com.google.gwt.xml.client XMLParser removeWhitespace

List of usage examples for com.google.gwt.xml.client XMLParser removeWhitespace

Introduction

In this page you can find the example usage for com.google.gwt.xml.client XMLParser removeWhitespace.

Prototype

public static void removeWhitespace(Node n) 

Source Link

Document

This method removes all Text nodes which are made up of only white space.

Usage

From source file:com.bramosystems.oss.player.playlist.client.impl.SAXParser.java

License:Apache License

public void parseDocument(Document doc) throws ParseException {
    XMLParser.removeWhitespace(doc);
    processNodes(doc.getChildNodes());
}

From source file:com.google.gwt.sample.simplexml.client.SimpleXML.java

License:Apache License

/**
 * Creates the xml representation of xmlText. xmlText is assumed to have been
 * validated for structure on the server.
 * /*from  w ww .  ja  va2 s .c  om*/
 * @param xmlText xml text
 * @param xmlParsed panel to display customer record
 */
private void customerPane(String xmlText, FlowPanel xmlParsed) {
    Document customerDom = XMLParser.parse(xmlText);
    Element customerElement = customerDom.getDocumentElement();
    // Must do this if you ever use a raw node list that you expect to be
    // all elements.
    XMLParser.removeWhitespace(customerElement);

    // Customer Name
    String nameValue = getElementTextValue(customerElement, "name");
    String title = "<h1>" + nameValue + "</h1>";
    HTML titleHTML = new HTML(title);
    xmlParsed.add(titleHTML);

    // Customer Notes
    String notesValue = getElementTextValue(customerElement, "notes");
    Label notesText = new Label();
    notesText.setStyleName(NOTES_STYLE);
    notesText.setText(notesValue);
    xmlParsed.add(notesText);

    // Pending orders UI setup
    FlexTable pendingTable = createOrderTable(xmlParsed, "Pending Orders");
    FlexTable completedTable = createOrderTable(xmlParsed, "Completed");
    completedTable.setText(0, 7, "Shipped by");

    // Fill Orders Table
    NodeList orders = customerElement.getElementsByTagName("order");
    int pendingRowPos = 0;
    int completedRowPos = 0;
    for (int i = 0; i < orders.getLength(); i++) {
        Element order = (Element) orders.item(i);
        HTMLTable table;
        int rowPos;
        if (order.getAttribute("status").equals("pending")) {
            table = pendingTable;
            rowPos = ++pendingRowPos;
        } else {
            table = completedTable;
            rowPos = ++completedRowPos;
        }
        int columnPos = 0;
        fillInOrderTableRow(customerElement, order, table, rowPos, columnPos);
    }
}

From source file:com.google.gwt.sample.simplexml.client.SimpleXML.java

License:Apache License

private void fillInOrderTableRow(Element customerElement, Element order, HTMLTable table, int rowPos,
        int columnPos) {
    // Order ID//  w w  w . j ava2 s  .com
    String orderId = order.getAttribute("id");
    table.setText(rowPos, columnPos++, orderId);

    // Item
    Element item = (Element) order.getElementsByTagName("item").item(0);
    String itemUPC = item.getAttribute("upc");
    String itemName = item.getFirstChild().getNodeValue();
    Label itemLabel = new Label(itemUPC);
    itemLabel.setTitle(itemName);
    table.setWidget(rowPos, columnPos++, itemLabel);

    // Ordered On
    String orderedOnValue = getElementTextValue(customerElement, "orderedOn");
    table.setText(rowPos, columnPos++, orderedOnValue);

    // Address
    Element address = (Element) order.getElementsByTagName("address").item(0);
    XMLParser.removeWhitespace(address);
    NodeList lst = address.getChildNodes();
    for (int j = 0; j < lst.getLength(); j++) {
        Element next = (Element) lst.item(j);
        String addressPartText = next.getFirstChild().getNodeValue();
        table.setText(rowPos, columnPos++, addressPartText);
    }

    // Shipped By (optional attribute)
    NodeList shippedByList = order.getElementsByTagName("shippingInfo");
    if (shippedByList.getLength() == 1) {
        Element shippedBy = (Element) shippedByList.item(0);
        // Depending upon the shipper, different attributes might be
        // available, so XML carries the display info
        FlexTable shippedByTable = new FlexTable();
        shippedByTable.getRowFormatter().setStyleName(0, USER_TABLE_LABEL_STYLE);
        shippedByTable.setBorderWidth(1);
        NodeList shippedByParts = shippedBy.getChildNodes();
        for (int j = 0; j < shippedByParts.getLength(); j++) {
            Node next = shippedByParts.item(j);
            Element elem = (Element) next;
            shippedByTable.setText(0, j, elem.getAttribute("title"));
            shippedByTable.setText(1, j, elem.getFirstChild().getNodeValue());
        }
        table.setWidget(rowPos, columnPos++, shippedByTable);
    }
}

From source file:com.sensia.gwt.relaxNG.RNGParser.java

License:Open Source License

public RNGGrammar parse(String url, String xml) {
    Document dom = XMLParser.parse(xml);
    XMLParser.removeWhitespace(dom);
    parseGrammar(url, dom.getDocumentElement());
    return grammar;
}

From source file:com.sensia.gwt.relaxNG.XMLSensorMLParser.java

License:Open Source License

/**
 * Parses the xml file.// w  w w  .  j  a  v a2 s .  c  o m
 *
 * @param url the url
 * @param xml the xml
 * @return the RNG grammar
 * @throws Exception the exception
 */
public RNGGrammar parse(String url, String xml) throws Exception {
    Document dom = XMLParser.parse(xml);
    XMLParser.removeWhitespace(dom);
    createGrammar(url, dom.getDocumentElement());
    return grammar;
}

From source file:de.decidr.modelingtoolbase.client.io.DWDLParser.java

License:Apache License

/**
 * Parses an xml dwdl document and created a {@link WorkflowModel} from it.
 * /*w  w  w  .  j a  v a  2 s. c o m*/
 * @param dwdl
 *            the dwdl to parse
 * @return {@link WorkflowModel}
 */
public WorkflowModel parse(String dwdl) {
    Document doc;
    //doc = XMLParser.createDocument();
    doc = XMLParser.parse(dwdl);
    XMLParser.removeWhitespace(doc);

    WorkflowModel workflow = new WorkflowModel();

    Element root = (Element) doc.getElementsByTagName(DWDLNames.root).item(0);

    createXmlProperties(root, workflow);
    createWorkflowProperties(root, workflow);

    /* Create variables and roles */
    List<Variable> variables = new ArrayList<Variable>();
    createVariables(root, variables);
    createRoles(root, variables);
    workflow.setVariables(variables);

    /* Create nodes */
    createChildNodeModels(root, workflow, workflow);

    return workflow;
}

From source file:net.dancioi.jcsphotogallery.client.model.ReadXMLGeneric.java

License:Open Source License

private void parseXMLString(String xmlText, int flag) {
    Document document = null;//from ww w  .  j a v a 2 s .  c om
    try {
        document = XMLParser.parse(xmlText);

        Element element = document.getDocumentElement();
        XMLParser.removeWhitespace(element);

        if (flag == ReadXML.FLAG_ALBUMS)
            albumsCallback(element);
        else if (flag == ReadXML.FLAG_ALBUMPHOTOS)
            albumPhotosCallback(element);
    } catch (DOMParseException de) {
        showException("File parse exception. Use a XML editor to avoid syntax errors in xml file.");
    }
}

From source file:org.gk.engine.client.utils.NodeUtils.java

License:Open Source License

/**
 * ?GUL//from  w  ww . j  ava2s .  c o m
 * 
 * @param gul
 * @return Document
 */
public static Document parseGUL(String gul) {
    Document doc = null;
    try {
        doc = XMLParser.parse(gul);
        // ?parsererrortag??
        NodeList nodes = doc.getElementsByTagName("parsererror");
        if (nodes != null && nodes.getLength() > 0) {
            throw new GULErrorException(nodes.item(0).getChildNodes() + "");
        }
        // IEnormalizeIE
        if (!GXT.isIE) {
            doc.normalize();
        }
        // ??
        XMLParser.removeWhitespace(doc);
    } catch (Exception e) {
        // parse?GULErrorException?
        throw new GULErrorException(e.getMessage());
    }
    return doc;
}

From source file:org.gk.ui.client.com.tree.xml.gkXMLTreeGridIC.java

License:Open Source License

@Override
public void setInfo(Object info) {
    // /*from   ww w.  j a v a 2  s  . c  o m*/
    store.removeAll();
    // ??GWT API?XML?doc
    doc = XMLParser.parse("<root>" + info + "</root>");
    XMLParser.removeWhitespace(doc.getFirstChild());
    // ?doc's nodestore?
    parseXmlDoc2Store(doc, store, cm);
}

From source file:org.gk.ui.client.com.tree.xml.gkXMLTreePanelIC.java

License:Open Source License

@Override
public void setInfo(Object info) {
    // //  w w  w . jav a2 s .c  o m
    store.removeAll();
    // ??GWT API?XML?doc
    if (RegExp.compile("</?[rR][oO][oO][tT][a-z0-9]*[^<>]*>").test(info.toString())) {
        doc = XMLParser.parse(info.toString());
    } else {
        doc = XMLParser.parse(
                "<ROOT id='" + getId() + "' name='" + getRootNodeInfo().get(NAME) + "'>" + info + "</ROOT>");
    }

    XMLParser.removeWhitespace(doc.getFirstChild());
    // ?doc's nodestore?
    parseXmlDoc2Store(doc, store);
    // ?tree
    tree.repaint();
    tree.fireEvent(Events.Render);
}