pdk.flow.xml.XmlAttr

contains functions to operate with XML Attr variables

This functions are based on Java org.w3c.dom package classes.

https://docs.oracle.com/en/java/javase/11/docs/api/java.xml/org/w3c/dom/package-summary.html

You can always rely on Java documentation and examples!

You can use functions from the pdk.floe.xml.XmlNode package for variables of type Attr, as the pdk.net.xml.Attr structure extends the pdk.net.xml.Node.

Attr objects inherit the Node structure, but since they are not actually child nodes of the element they describe, the DOM does not consider them part of the document tree. Thus, the Node attributes parentNode, previousSibling, and nextSibling have a null value for Attr objects. The DOM takes the view that attributes are properties of elements rather than having a separate identity from the elements they are associated with; this should make it more efficient to implement such features as default attributes associated with all elements of a given type. Furthermore, Attr nodes may not be immediate children of a DocumentFragment. However, they can be associated with Element nodes contained within a DocumentFragment. In short, users and implementors of the DOM need to be aware that Attr nodes have some things in common with other objects inheriting the Node structure, but they also are quite distinct.

The attribute's effective value is determined as follows: if this attribute has been explicitly assigned any value, that value is the attribute's effective value; otherwise, if there is a declaration for this attribute, and that declaration includes a default value, then that default value is the attribute's effective value; otherwise, the attribute does not exist on this element in the structure model until it has been explicitly added. Note that the Node.nodeValue attribute on the Attr instance can also be used to retrieve the string version of the attribute's value(s).

If the attribute was not explicitly given a value in the instance document but has a default value provided by the schema associated with the document, an attribute node will be created with specified set to false. Removing attribute nodes for which a default value is defined in the schema generates a new attribute node with the default value and specified set to false. If validation occurred while invoking XmlDocument.normalizeDocument(), attribute nodes with specified equals to false are recomputed according to the default attribute values provided by the schema. If no default value is associate with this attribute in the schema, the attribute node is discarded.

In XML, where the value of an attribute can contain entity references, the child nodes of the Attr node may be either Text or EntityReference nodes.

The following table gives some examples of the relations between the attribute value in the original document (parsed attribute), the value as exposed in the DOM, and the serialization of the value:

Examples
Parsed attribute value
Initial Attr.value
Serialized attribute value

Character reference

Built-in character entity

Literal newline between

Normalized newline between

All functions


getName

Returns the name of the input attribute. If result of XmlNode.localName function is different from null, this attribute is a qualified name.

Arguments:

Result:

Possible exceptions

Example:

XML Document

<order id="1">
    <book id="b_1" name="Harry Potter and the Philosopher's Stone"></book>
</order>
attr :: pdk.net.xml.Attr -> [id="1"]

XmlAttr.getName(attr) :: pdk.core.String ->
output = "id"

getSpecified

True if this attribute was explicitly given a value in the instance document, false otherwise. If the application changed the value of this attribute node (even if it ends up having the same value as the default value) then it is set to true. The implementation may handle attributes with default values from other schemas similarly but applications should use XmlDocument.normalizeDocument function to guarantee this information is up-to-date.

Arguments:

Result:

Possible exceptions

Example:

XML Document

<order id="1">
    <book id="b_1" name="Harry Potter and the Philosopher's Stone"></book>
</order>
attr :: pdk.net.xml.Attr -> [id="1"]

XmlAttr.getSpecified(attr) :: pdk.core.Boolean ->
output = true

getValue

On retrieval, the value of the attribute is returned as a string. Character and general entity references are replaced with their values. See also the function XmlElement.getAttribute.

Arguments:

Result:

Possible exceptions

Example:

XML Document

<order id="1">
    <book id="b_1" name="Harry Potter and the Philosopher's Stone"></book>
</order>
attr :: pdk.net.xml.Attr -> [id="1"]

XmlAttr.getValue(attr) :: pdk.core.String ->
output = "1"

setValue

Creates a Text node with the unparsed contents of the string, i.e. any characters that an XML processor would recognize as markup are instead treated as literal text. See also the function XmlElement.setAttribute. Some specialized implementations, such as some [SVG 1.1] implementations, may do normalization automatically, even after mutation; in such case, the value on retrieval may differ from the value on setting.

Arguments:

Result:

  • No variable is returned. The input attribute value has been changed

Possible exceptions

Example:

XML Document

<order id="1">
    <book id="b_1" name="Harry Potter and the Philosopher's Stone"></book>
</order>
attr :: pdk.net.xml.Attr -> [id="1"]
newValue :: pdk.core.String = "2"

XmlAttr.setValue(attr, newValue) :: Void ->
attr -> [id="2"]

getOwnerElement

The Element node this attribute is attached to or null if this attribute is not in us

Arguments:

Result:

Possible exceptions

Example:

XML Document

<order id="1">
    <book id="b_1" name="Harry Potter and the Philosopher's Stone"></book>
</order>
attr :: pdk.net.xml.Attr -> [id="1"]

XmlAttr.getOwnerElement(attr) :: pdk.net.xml.Element ->
output = <order id="1">

getSchemaTypeInfo

The type information associated with this attribute. While the type information contained in this attribute is guarantee to be correct after loading the document or invoking XmlDocument.normalizeDocument function, schemaTypeInfo may not be reliable if the node was moved.

Arguments:

Result:

Possible exceptions


isId

Returns whether this attribute is known to be of type ID (i.e. to contain an identifier for its owner element) or not. When it is and its value is unique, the ownerElement of this attribute can be retrieved using the method XmlDocument.getElementById

Arguments:

Result:

Possible exceptions

Last updated