Class ProcessingInstruction

java.lang.Object
org.jsoup.nodes.Node
org.jsoup.nodes.LeafNode
org.jsoup.nodes.ProcessingInstruction
All Implemented Interfaces:
Cloneable

public class ProcessingInstruction extends LeafNode
A processing instruction with a target and data, such as <?marker name="country-options"?>.

The XML declaration <?xml ...?> is represented by XmlDeclaration.

If you access this node's attributes, directly or through an attribute selector, the instruction data is parsed into an Attributes object using the owning document's parser settings, or HTML settings if the node is detached. The attributes then determine the instruction data.

Since:
1.24.1
  • Constructor Details

    • ProcessingInstruction

      public ProcessingInstruction(String target, String data)
      Creates a processing instruction with the supplied target and data.
      Parameters:
      target - the target following <?
      data - the data following the target, without the separating whitespace or closing ?>
  • Method Details

    • nodeName

      public String nodeName()
      Returns the node name #processing-instruction.
      Specified by:
      nodeName in class Node
      Returns:
      node name
    • target

      public String target()
      Returns the instruction target.
      Returns:
      the target following <?
    • data

      public String data()
      Returns the data following the target. If the attributes have been accessed, returns their serialized form.
      Returns:
      the instruction data
    • data

      public ProcessingInstruction data(String data)
      Replaces the instruction data. If the attributes have been accessed, parses the new data and updates the existing Attributes object.
      Parameters:
      data - the new data, without the separating whitespace or closing ?>
      Returns:
      this node, for chaining
    • nodeValue

      public String nodeValue()
      Returns the instruction data as this node's value.
      Overrides:
      nodeValue in class LeafNode
      Returns:
      the node's value
    • attr

      public String attr(String key)
      Description copied from class: Node
      Get an attribute's value by its key. Case insensitive

      To get an absolute URL from an attribute that may be a relative URL, prefix the key with abs:, which is a shortcut to the Node.absUrl(java.lang.String) method.

      E.g.:
      String url = a.attr("abs:href");
      Overrides:
      attr in class LeafNode
      Parameters:
      key - The attribute key.
      Returns:
      The attribute, or empty string if not present (to avoid nulls).
      See Also:
    • attr

      public ProcessingInstruction attr(String key, String value)
      Description copied from class: Node
      Set an attribute (key=value). If the attribute already exists, it is replaced. The attribute key comparison is case insensitive. The key will be set with case sensitivity as set in the parser settings.
      Overrides:
      attr in class LeafNode
      Parameters:
      key - The attribute key.
      value - The attribute value.
      Returns:
      this (for chaining)
    • attributesSize

      public int attributesSize()
      Description copied from class: Node
      Get the number of attributes that this Node has.
      Overrides:
      attributesSize in class Node
      Returns:
      the number of attributes
    • clearAttributes

      public ProcessingInstruction clearAttributes()
      Description copied from class: Node
      Clear (remove) each of the attributes in this node.
      Overrides:
      clearAttributes in class Node
      Returns:
      this, for chaining
    • clone

      public ProcessingInstruction clone()
      Description copied from class: Node
      Create a stand-alone, deep copy of this node, and all of its children. The cloned node will have no siblings.

      • If this node is a LeafNode, the clone will have no parent.
      • If this node is an Element, the clone will have a simple owning Document to retain the configured output settings and parser.

      The cloned node may be adopted into another Document or node structure using Element.appendChild(Node).

      Overrides:
      clone in class Node
      Returns:
      a stand-alone cloned node, including clones of any children
      See Also: