public static void main(String args[]) {
    QApplication.initialize(args);
    String localName = "myName";
    QIODevice device;
    {
      QXmlItem value = new QXmlItem();
      QXmlQuery query = new QXmlQuery();
      // ! [0]
      query.bindVariable(new QXmlName(query.namePool(), localName), value);
      // ! [0]
    }

    // ! [1]
    QByteArray myDocument = new QByteArray();
    QBuffer buffer = new QBuffer(myDocument); // This is a QIODevice.
    buffer.open(QIODevice.OpenModeFlag.ReadOnly);
    QXmlQuery query = new QXmlQuery();
    query.bindVariable("myDocument", buffer);
    query.setQuery("declare variable $myDocument external; doc($myDocument)");
    // ! [1]

    // ! [2]
    query.bindVariable(new QXmlName(query.namePool(), localName), device);
    // ! [2]

  }
  public static void main(String args[]) {
    QApplication.initialize(args);
    // ! [0]
    QXmlQuery query = new QXmlQuery();
    query.setQuery("<e/>, 1, 'two'");
    QXmlResultItems result = new QXmlResultItems();

    if (query.isValid()) {
      query.evaluateToResult(result);
      QXmlItem item = result.next();
      while (!item.isNull()) {
        // Use item
        item = result.next();
      }

      if (result.hasError()) throw new RuntimeException("Runtime error!");
    }
    // ! [0]
  }