Class ProcessingInstruction
- java.lang.Object
-
- eu.maveniverse.domtrip.Node
-
- eu.maveniverse.domtrip.ProcessingInstruction
-
public class ProcessingInstruction extends Node
Represents an XML processing instruction, preserving exact formatting and content.Processing instructions (PIs) provide a way to include application-specific instructions in XML documents. They follow the syntax
<?target data?>where the target identifies the application and the data contains the instruction.Processing Instruction Handling:
- Target Preservation - Maintains the PI target exactly as written
- Data Preservation - Preserves the instruction data
- Format Preservation - Keeps original formatting when unmodified
Common Processing Instructions:
<?xml version="1.0" encoding="UTF-8"?>- XML declaration<?xml-stylesheet type="text/xsl" href="style.xsl"?>- Stylesheet reference<?php echo "Hello World"; ?>- PHP code
Usage Examples:
// Create processing instruction ProcessingInstruction pi = new ProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"style.xsl\""); // Create using factory methods ProcessingInstruction factoryPI = ProcessingInstruction.of("xml-stylesheet", "type=\"text/css\" href=\"style.css\""); ProcessingInstruction simplePI = ProcessingInstruction.of("target"); // Create and modify with fluent API ProcessingInstruction fluentPI = ProcessingInstruction.of("target", "data") .target("new-target") .data("new data"); // Add to document document.addChild(pi);
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class eu.maveniverse.domtrip.Node
Node.NodeType
-
-
Field Summary
-
Fields inherited from class eu.maveniverse.domtrip.Node
modified, parent, precedingWhitespace
-
-
Constructor Summary
Constructors Constructor Description ProcessingInstruction(java.lang.String originalContent)ProcessingInstruction(java.lang.String target, java.lang.String data)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description DomTripVisitor.Actionaccept(DomTripVisitor visitor)Accepts a visitor for depth-first tree traversal.ProcessingInstructionclone()Deprecated.Usecopy()instead.ProcessingInstructioncopy()Creates a deep copy of this node.java.lang.Stringdata()ProcessingInstructiondata(java.lang.String data)booleanequals(java.lang.Object obj)inthashCode()static ProcessingInstructionof(java.lang.String target)Creates a processing instruction with only a target (no data).static ProcessingInstructionof(java.lang.String target, java.lang.String data)Creates a processing instruction with the specified target and data.java.lang.StringoriginalContent()voidoriginalContent(java.lang.String originalContent)ProcessingInstructionparent(ContainerNode parent)Sets the parent container node of this node.ProcessingInstructionprecedingWhitespace(java.lang.String whitespace)Sets the whitespace that precedes this node.java.lang.Stringtarget()ProcessingInstructiontarget(java.lang.String target)java.lang.StringtoString()voidtoXml(java.lang.StringBuilder sb)Serializes this node to XML, appending to the provided StringBuilder.Node.NodeTypetype()Returns the type of this XML node.-
Methods inherited from class eu.maveniverse.domtrip.Node
clearModified, depth, document, isDescendantOf, isModified, markModified, nextSibling, nextSiblingElement, parent, parentElement, precedingWhitespace, previousSibling, previousSiblingElement, siblingIndex, toXml
-
-
-
-
Method Detail
-
parent
public ProcessingInstruction parent(ContainerNode parent)
Sets the parent container node of this node.This method is typically called automatically when adding nodes to containers. Manual use should be done carefully to maintain tree consistency.
- Overrides:
parentin classNode- Parameters:
parent- the parent container node to set, or null to clear the parent- Returns:
- this processing instruction for method chaining
- See Also:
Node.parent()
-
precedingWhitespace
public ProcessingInstruction precedingWhitespace(java.lang.String whitespace)
Sets the whitespace that precedes this node.This method allows control over the whitespace formatting before this node when serializing to XML.
- Overrides:
precedingWhitespacein classNode- Parameters:
whitespace- the whitespace string to set, null is treated as empty string- Returns:
- this processing instruction for method chaining
- See Also:
Node.precedingWhitespace()
-
target
public java.lang.String target()
-
target
public ProcessingInstruction target(java.lang.String target)
-
data
public java.lang.String data()
-
data
public ProcessingInstruction data(java.lang.String data)
-
originalContent
public java.lang.String originalContent()
-
originalContent
public void originalContent(java.lang.String originalContent)
-
type
public Node.NodeType type()
Description copied from class:NodeReturns the type of this XML node.The node type determines the node's behavior and capabilities. This method must be implemented by all concrete node classes.
- Specified by:
typein classNode- Returns:
- the
Node.NodeTypeof this node
-
accept
public DomTripVisitor.Action accept(DomTripVisitor visitor)
Accepts a visitor for depth-first tree traversal.This method implements the visitor pattern, allowing structured traversal of the XML tree with enter/exit lifecycle callbacks. Each node type dispatches to the appropriate visitor method.
- Specified by:
acceptin classNode- Parameters:
visitor- the visitor to accept- Returns:
- the action returned by the visitor, indicating how traversal should proceed
- Since:
- 1.3.0
- See Also:
DomTripVisitor
-
toXml
public void toXml(java.lang.StringBuilder sb)
Description copied from class:NodeSerializes this node to XML, appending to the provided StringBuilder.This method is more efficient than
Node.toXml()when building larger XML documents as it avoids string concatenation overhead.- Specified by:
toXmlin classNode- Parameters:
sb- the StringBuilder to append the XML content to- See Also:
Node.toXml()
-
copy
public ProcessingInstruction copy()
Creates a deep copy of this node.The copied node will have:
- All properties copied from the original
- All child nodes recursively copied (for container nodes)
- Whitespace and formatting properties preserved
- No parent (parent is set to null)
The copied node and its descendants will have their parent-child relationships properly established within the copied subtree.
-
clone
@Deprecated public ProcessingInstruction clone()
Deprecated.Usecopy()instead.Creates a deep copy of this processing instruction.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
of
public static ProcessingInstruction of(java.lang.String target, java.lang.String data)
Creates a processing instruction with the specified target and data.Factory method following modern Java naming conventions.
- Parameters:
target- the processing instruction targetdata- the processing instruction data- Returns:
- a new ProcessingInstruction
-
of
public static ProcessingInstruction of(java.lang.String target)
Creates a processing instruction with only a target (no data).Factory method for simple processing instructions.
- Parameters:
target- the processing instruction target- Returns:
- a new ProcessingInstruction with empty data
-
-