TYPE_COMMENT, TYPE_ELEMENT, TYPE_PROCESSING_INSTRUCTION, TYPE_TEXT
Constructor and Description |
---|
XmlElement() |
Modifier and Type | Method and Description |
---|---|
XmlElement |
addAttribute(java.lang.String name,
java.lang.String value)
Add an attribute to this element.
|
XmlElement |
addAttributeWithQName(XmlName name,
java.lang.String value)
Add an attribute to this element.
|
XmlElement |
addChild(XmlNode child)
Add a child node to this element.
|
XmlElement |
addComment(java.lang.String text)
Add a comment node to this element.
|
XmlElement |
addElement(XmlElement child)
Add an element node to this element.
|
XmlElement |
addElements(XmlElementList elements)
Add a list of elements to this element.
|
XmlElement |
addText(java.lang.String text)
Add a text node to this element.
|
void |
appendTo(com.sap.cloud.server.odata.core.CharBuffer buffer)
|
void |
appendTo(com.sap.cloud.server.odata.core.CharBuffer buffer,
int indent)
Append the textual representation of this element to a buffer.
|
XmlElementList |
elementsNamed(java.lang.String name)
Lookup all child elements with a specified name.
|
java.lang.String |
getAttribute(java.lang.String name)
Lookup the value for the attribute with a specified name.
|
XmlAttributeList |
getAttributes()
Return list of attributes for this element.
|
XmlNodeList |
getChildNodes()
Return list of child nodes for this element.
|
XmlCommentList |
getComments()
Return a list of the comment nodes in this element.
|
XmlElement |
getElement(java.lang.String name)
Lookup first child element with a specified name.
|
XmlElementList |
getElements()
Return a list of the element nodes in this element.
|
int |
getLineNumber()
Return line number (starting at 1) if this element was parsed from a file.
|
java.lang.String |
getLocalName()
Return local element name, without namespace prefix, e.g.
|
java.lang.String |
getName()
Return element name, possibly qualified by namespace prefix, e.g.
|
java.lang.String |
getNamespaceURI()
Return (nullable) Namespace URI, if known.
|
java.lang.String |
getPrefix()
Return (nullable) Optional namespace prefix, e.g.
|
java.lang.String |
getRequiredAttribute(java.lang.String name)
Lookup the value for the attribute with a specified name.
|
XmlElement |
getRequiredElement(java.lang.String name)
Lookup first child element with a specified name.
|
java.lang.String |
getSourceFile()
Return (nullable) Source file name (if available).
|
java.lang.String |
getText()
Return a combination of all the text nodes in this element.
|
int |
getType()
Return XmlNode.TYPE_ELEMENT.
|
boolean |
hasPrefix()
Return is
XmlElement.prefix non-null? |
static XmlElement |
parse(java.lang.String xml)
Parse a string to an element.
|
static XmlElement |
parseMixed(java.lang.String xml)
|
static XmlElement |
parseMixed(java.lang.String xml,
boolean mixed)
Parse a string to an element.
|
void |
removeAttribute(java.lang.String name)
Remove the value for the attribute with a specified name.
|
void |
resolveNamespaces()
Traverse the element hierachy starting at this element, ensuring that
every node has the
XmlElement.namespaceURI set according to the "xmlns"
attributes and namespace prefixes encountered in the nodes. |
XmlElement |
setAttribute(java.lang.String name,
java.lang.String value)
Set an attribute of this element (replace attribute value if the attribute is already defined, otherwise add the attribute).
|
void |
setAttributes(XmlAttributeList value)
Set list of attributes for this element.
|
XmlElement |
setAttributeWithQName(XmlName name,
java.lang.String value)
Set an attribute of this element (replace attribute value if the attribute is already defined, otherwise add the attribute).
|
void |
setChildNodes(XmlNodeList value)
Set list of child nodes for this element.
|
void |
setLineNumber(int value)
Set line number (starting at 1) if this element was parsed from a file.
|
void |
setLocalName(java.lang.String value)
Set local element name, without namespace prefix, e.g.
|
void |
setName(java.lang.String value)
Set element name, possibly qualified by namespace prefix, e.g.
|
void |
setNamespaceURI(java.lang.String value)
Set namespace URI, if known.
|
void |
setPrefix(java.lang.String value)
Set optional namespace prefix, e.g.
|
void |
setSourceFile(java.lang.String value)
Set source file name (if available).
|
java.lang.String |
toString()
Return the element, without an XML declaration.
|
static XmlElement |
withName(java.lang.String name)
Convenience function for constructing an element node with specified name.
|
static XmlElement |
withQName(XmlName name)
Convenience function for constructing an element node with specified name.
|
public XmlElement addAttribute(java.lang.String name, java.lang.String value)
Add an attribute to this element.
name
- Attribute name.value
- Attribute value.public XmlElement addAttributeWithQName(XmlName name, java.lang.String value)
Add an attribute to this element.
name
- Attribute name.value
- Attribute value.public XmlElement addChild(XmlNode child)
Add a child node to this element.
child
- Child node.public XmlElement addComment(java.lang.String text)
Add a comment node to this element.
text
- Comment text.public XmlElement addElement(XmlElement child)
Add an element node to this element.
child
- Child element.public XmlElement addElements(XmlElementList elements)
Add a list of elements to this element.
elements
- Child elements.public XmlElement addText(java.lang.String text)
Add a text node to this element.
text
- Text value.public void appendTo(com.sap.cloud.server.odata.core.CharBuffer buffer)
buffer
- Buffer parameter.public void appendTo(com.sap.cloud.server.odata.core.CharBuffer buffer, int indent)
Append the textual representation of this element to a buffer.
buffer
- Buffer to receive textual representation.indent
- Indent level for indented pretty-printing. Pass -1 to disable pretty-printing.public XmlElementList elementsNamed(java.lang.String name)
Lookup all child elements with a specified name.
name
- Element name, to be compared with XmlElement.name
and XmlElement.localName
of child elements when matching.public java.lang.String getAttribute(java.lang.String name)
Lookup the value for the attribute with a specified name.
name
- Attribute name, to be compared with XmlElement.name
and XmlElement.localName
of attributes when matching.public XmlAttributeList getAttributes()
Return list of attributes for this element.
public XmlNodeList getChildNodes()
Return list of child nodes for this element.
public XmlCommentList getComments()
Return a list of the comment nodes in this element. Note: the list is recalculated every time this property is accessed. For best performance, callers are advised to save the resulting value if it will be used multiple times.
public XmlElement getElement(java.lang.String name)
Lookup first child element with a specified name.
name
- Element name, to be compared with XmlElement.name
and XmlElement.localName
of child elements when matching.public XmlElementList getElements()
Return a list of the element nodes in this element. Note: the list is recalculated every time this property is accessed. For best performance, callers are advised to save the resulting value if it will be used multiple times.
public int getLineNumber()
Return line number (starting at 1) if this element was parsed from a file. Otherwise zero.
public java.lang.String getLocalName()
Return local element name, without namespace prefix, e.g. "MyElement".
public java.lang.String getName()
Return element name, possibly qualified by namespace prefix, e.g. "MyElement" or "myns:MyElement".
public java.lang.String getNamespaceURI()
Return (nullable) Namespace URI, if known. Will not be valid unless XmlElement.resolveNamespaces
has been called for the element hierarchy containing this element.
XmlElement.resolveNamespaces
has been called for the element hierarchy containing this element.public java.lang.String getPrefix()
Return (nullable) Optional namespace prefix, e.g. "myns" or null
.
null
.public java.lang.String getRequiredAttribute(java.lang.String name)
Lookup the value for the attribute with a specified name.
XmlException
if no match is found.
name
- Attribute name, to be compared with XmlElement.name
and XmlElement.localName
of attributes when matching.public XmlElement getRequiredElement(java.lang.String name)
Lookup first child element with a specified name.
XmlException
if no match is found.
name
- Element name, to be compared with XmlElement.name
and XmlElement.localName
of child elements when matching.public java.lang.String getSourceFile()
Return (nullable) Source file name (if available). Otherwise null
.
null
.public java.lang.String getText()
Return a combination of all the text nodes in this element. Note: the text is recalculated every time this property is accessed. For best performance, callers are advised to save the resulting value if it will be used multiple times.
public int getType()
Return XmlNode.TYPE_ELEMENT.
public boolean hasPrefix()
Return is XmlElement.prefix
non-null?
XmlElement.prefix
non-null?public static XmlElement parse(java.lang.String xml)
Parse a string to an element. Equivalent to parseMixed(xml, false)
xml
- Text to be parsed.public static XmlElement parseMixed(java.lang.String xml)
xml
- Xml parameter.public static XmlElement parseMixed(java.lang.String xml, boolean mixed)
Parse a string to an element.
xml
- Text to be parsed.mixed
- true
if mixed content is permitted, false
otherwise. Parsing may be faster with mixed
= false
, since text nodes can be omitted from elements which have non-text content.public void removeAttribute(java.lang.String name)
Remove the value for the attribute with a specified name.
name
- Attribute name, to be compared with XmlElement.name
and XmlElement.localName
of attributes when matching.public void resolveNamespaces()
Traverse the element hierachy starting at this element, ensuring that
every node has the XmlElement.namespaceURI
set according to the "xmlns"
attributes and namespace prefixes encountered in the nodes.
public XmlElement setAttribute(java.lang.String name, java.lang.String value)
Set an attribute of this element (replace attribute value if the attribute is already defined, otherwise add the attribute).
name
- Attribute name.value
- Attribute value.public XmlElement setAttributeWithQName(XmlName name, java.lang.String value)
Set an attribute of this element (replace attribute value if the attribute is already defined, otherwise add the attribute).
name
- Attribute name.value
- Attribute value.public void setAttributes(XmlAttributeList value)
Set list of attributes for this element.
value
- List of attributes for this element.public void setChildNodes(XmlNodeList value)
Set list of child nodes for this element.
value
- List of child nodes for this element.public void setLineNumber(int value)
Set line number (starting at 1) if this element was parsed from a file. Otherwise zero.
value
- Line number (starting at 1) if this element was parsed from a file. Otherwise zero.public void setLocalName(java.lang.String value)
Set local element name, without namespace prefix, e.g. "MyElement".
value
- Local element name, without namespace prefix, e.g. "MyElement".public void setName(java.lang.String value)
Set element name, possibly qualified by namespace prefix, e.g. "MyElement" or "myns:MyElement".
value
- Element name, possibly qualified by namespace prefix, e.g. "MyElement" or "myns:MyElement".public void setNamespaceURI(java.lang.String value)
Set namespace URI, if known. Will not be valid unless XmlElement.resolveNamespaces
has been called for the element hierarchy containing this element.
value
- Namespace URI, if known. Will not be valid unless XmlElement.resolveNamespaces
has been called for the element hierarchy containing this element.public void setPrefix(java.lang.String value)
Set optional namespace prefix, e.g. "myns" or null
.
value
- Optional namespace prefix, e.g. "myns" or null
.public void setSourceFile(java.lang.String value)
Set source file name (if available). Otherwise null
.
value
- Source file name (if available). Otherwise null
.public java.lang.String toString()
Return the element, without an XML declaration.
toString
in class java.lang.Object
public static XmlElement withName(java.lang.String name)
Convenience function for constructing an element node with specified name.
let e = XmlAttribute.withName("e")
.addAttribute(XmlAttribute.withName("a").andValue("v"))
.addComment("c")
.addElement(XmlElement.withName("x"))
.addText("t");
name
- The element name.public static XmlElement withQName(XmlName name)
Convenience function for constructing an element node with specified name.
name
- The element name.