Qt 4.8
Static Public Functions | List of all members
Document Class Reference
Inheritance diagram for Document:
Node

Static Public Functions

static QScriptValue documentElement (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue load (QScriptEngine *engine, const QByteArray &data)
 
static QScriptValue prototype (QScriptEngine *)
 
static QScriptValue xmlEncoding (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue xmlStandalone (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue xmlVersion (QScriptContext *context, QScriptEngine *engine)
 
- Static Public Functions inherited from Node
static QScriptValue attributes (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue childNodes (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue create (QScriptEngine *, NodeImpl *)
 
static QScriptValue firstChild (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue lastChild (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue nextSibling (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue nodeName (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue nodeType (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue nodeValue (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue parentNode (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue previousSibling (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue prototype (QScriptEngine *)
 

Additional Inherited Members

- Public Functions inherited from Node
bool isNull () const
 
 Node ()
 
 Node (const Node &o)
 
 ~Node ()
 
- Public Variables inherited from Node
NodeImpld
 

Detailed Description

Definition at line 312 of file qdeclarativexmlhttprequest.cpp.

Functions

◆ documentElement()

QScriptValue Document::documentElement ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 913 of file qdeclarativexmlhttprequest.cpp.

914 {
915  Node document = qscriptvalue_cast<Node>(context->thisObject());
916  if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue();
917 
918  return Node::create(engine, static_cast<DocumentImpl *>(document.d)->root);
919 }
T qscriptvalue_cast(const QScriptValue &)
bool isNull() const
static QScriptValue create(QScriptEngine *, NodeImpl *)
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.

◆ load()

QScriptValue Document::load ( QScriptEngine engine,
const QByteArray data 
)
static

Definition at line 630 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_responseXML().

631 {
632  Q_ASSERT(engine);
633 
634  DocumentImpl *document = 0;
635  QStack<NodeImpl *> nodeStack;
636 
637  QXmlStreamReader reader(data);
638 
639  while (!reader.atEnd()) {
640  switch (reader.readNext()) {
642  break;
644  break;
646  Q_ASSERT(!document);
647  document = new DocumentImpl;
648  document->document = document;
649  document->version = reader.documentVersion().toString();
650  document->encoding = reader.documentEncoding().toString();
651  document->isStandalone = reader.isStandaloneDocument();
652  break;
654  break;
656  {
657  Q_ASSERT(document);
658  NodeImpl *node = new NodeImpl;
659  node->document = document;
660  node->namespaceUri = reader.namespaceUri().toString();
661  node->name = reader.name().toString();
662  if (nodeStack.isEmpty()) {
663  document->root = node;
664  } else {
665  node->parent = nodeStack.top();
666  node->parent->children.append(node);
667  }
668  nodeStack.append(node);
669 
670  foreach (const QXmlStreamAttribute &a, reader.attributes()) {
671  NodeImpl *attr = new NodeImpl;
672  attr->document = document;
673  attr->type = NodeImpl::Attr;
674  attr->namespaceUri = a.namespaceUri().toString();
675  attr->name = a.name().toString();
676  attr->data = a.value().toString();
677  attr->parent = node;
678  node->attributes.append(attr);
679  }
680  }
681  break;
683  nodeStack.pop();
684  break;
686  {
687  NodeImpl *node = new NodeImpl;
688  node->document = document;
689  node->type = reader.isCDATA()?NodeImpl::CDATA:NodeImpl::Text;
690  node->parent = nodeStack.top();
691  node->parent->children.append(node);
692  node->data = reader.text().toString();
693  }
694  break;
696  break;
698  break;
700  break;
702  break;
703  }
704  }
705 
706  if (!document || reader.hasError()) {
707  if (document) D(document);
708  return engine->nullValue();
709  }
710 
711  QScriptValue instance = engine->newObject();
712  instance.setPrototype(Document::prototype(engine));
713  Node documentNode;
714  documentNode.d = document;
715  return engine->newVariant(instance, QVariant::fromValue(documentNode));
716 }
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
QStringRef value() const
Returns the attribute&#39;s value.
Definition: qxmlstream.h:156
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
long ASN1_INTEGER_get ASN1_INTEGER * a
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
The QXmlStreamAttribute class represents a single XML attribute.
Definition: qxmlstream.h:135
QList< NodeImpl * > attributes
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define D(arg)
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QScriptValue newObject()
Creates a QtScript object of class Object.
QStringRef name() const
Returns the attribute&#39;s local name.
Definition: qxmlstream.h:149
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
QList< NodeImpl * > children
void setPrototype(const QScriptValue &prototype)
If this QScriptValue is an object, sets the internal prototype (__proto__ property) of this object to...
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
static QScriptValue prototype(QScriptEngine *)
The QXmlStreamReader class provides a fast parser for reading well-formed XML via a simple streaming ...
Definition: qxmlstream.h:290
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue newVariant(const QVariant &value)
Creates a QtScript object holding the given variant value.
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72
DocumentImpl * document
QStringRef namespaceUri() const
Returns the attribute&#39;s resolved namespaceUri, or an empty string reference if the attribute does not...
Definition: qxmlstream.h:148

◆ prototype()

QScriptValue Document::prototype ( QScriptEngine engine)
static

Definition at line 617 of file qdeclarativexmlhttprequest.cpp.

Referenced by load().

618 {
619  QScriptValue proto = engine->newObject();
620  proto.setPrototype(Node::prototype(engine));
621 
626 
627  return proto;
628 }
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
static QScriptValue xmlStandalone(QScriptContext *context, QScriptEngine *engine)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QScriptValue prototype(QScriptEngine *)
static QScriptValue documentElement(QScriptContext *context, QScriptEngine *engine)
QScriptValue newObject()
Creates a QtScript object of class Object.
static QScriptValue xmlVersion(QScriptContext *context, QScriptEngine *engine)
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
void setPrototype(const QScriptValue &prototype)
If this QScriptValue is an object, sets the internal prototype (__proto__ property) of this object to...
static QScriptValue xmlEncoding(QScriptContext *context, QScriptEngine *engine)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ xmlEncoding()

QScriptValue Document::xmlEncoding ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 937 of file qdeclarativexmlhttprequest.cpp.

938 {
939  Node document = qscriptvalue_cast<Node>(context->thisObject());
940  if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue();
941 
942  return QScriptValue(static_cast<DocumentImpl *>(document.d)->encoding);
943 }
T qscriptvalue_cast(const QScriptValue &)
bool isNull() const
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ xmlStandalone()

QScriptValue Document::xmlStandalone ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 921 of file qdeclarativexmlhttprequest.cpp.

922 {
923  Node document = qscriptvalue_cast<Node>(context->thisObject());
924  if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue();
925 
926  return QScriptValue(static_cast<DocumentImpl *>(document.d)->isStandalone);
927 }
T qscriptvalue_cast(const QScriptValue &)
bool isNull() const
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ xmlVersion()

QScriptValue Document::xmlVersion ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 929 of file qdeclarativexmlhttprequest.cpp.

930 {
931  Node document = qscriptvalue_cast<Node>(context->thisObject());
932  if (document.isNull() || document.d->type != NodeImpl::Document) return engine->undefinedValue();
933 
934  return QScriptValue(static_cast<DocumentImpl *>(document.d)->version);
935 }
T qscriptvalue_cast(const QScriptValue &)
bool isNull() const
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

The documentation for this class was generated from the following file: