![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |
#include <SFXXMLElement.hpp>
class SFXXMLElement : public SFXXMLNode;
SFMTYPEDEFCLASS(SFXXMLElement)


An Element node(SFXXMLElement) contains an element of the XML document.
An Attribute node(SFXXMLAttribute) can be set to the Element node using the functions such as SFXXMLElement::SetAttributeNode, SFXXMLElement::SetAttribute.
The Attribute node of the Element node can be obtained using the functions such as SFXXMLElement::GetAttributeNode, SFXXMLElement::GetAttributes.
SFXXMLNode | SFXXMLAttribute | SFXXMLCDATASection | SFXXMLComment | SFXXMLDocument | SFXXMLDocumentFragment | SFXXMLDocumentType | SFXXMLEntity | SFXXMLEntityReference | SFXXMLNotation | SFXXMLProcessingInstruction | SFXXMLText
| Constructor/Destructor |
|---|
|
SFXXMLElement(
SFXXMLDocumentPtr owner
, SFXAnsiStringConstRef name
) Constructor of SFXXMLElement class.
|
|
SFXXMLElement(
SFXXMLDocumentPtr owner
, SFXAnsiStringConstRef name
, SFXAnsiStringConstRef namespaceURI
) Constructor of SFXXMLElement class.
|
|
SFXXMLElement(
SFXXMLElementConstRef other
, Bool deep = false
) Constructor of SFXXMLElement class.
|
|
~SFXXMLElement( Void ) Destructor of SFXXMLElement class.
|
| Public Functions | |
|---|---|
| SFCError |
AppendChild(
SFXXMLNodeConstPtr newchild
) Append a specified child node at the end.
|
| SFCError |
CloneNode(
SFXXMLNodeHandle clonenode
, Bool deep
) Create a copy of this node.
|
| Bool |
EqualNode(
SFXXMLNodeConstPtr arg
) Check whether this node equals a specified node or not.
|
| ACharConstPtr |
GetAttribute(
SFXAnsiStringConstRef name
) Get the attribute value by name.
|
| SFXXMLAttributePtr |
GetAttributeNode(
SFXAnsiStringConstRef name
) Get the Attribute node by name.
|
| DOMNamedNodeMapPtr |
GetAttributes( Void ) Get all the Attribute nodes.
|
| DOMNodeListPtr |
GetChildNodes( Void ) Get all the child nodes.
|
| DOMNodeListPtr |
GetElementsByTagName(
SFXAnsiStringConstRef name
) Get all the Element nodes that match a specified tag name.
|
| SFXXMLNodePtr |
GetFirstChild( Void ) Get the first child node.
|
| SFXXMLNodePtr |
GetLastChild( Void ) Get the last child node.
|
| ACharConstPtr |
GetLocalName( Void ) Get the local name.
|
| ACharConstPtr |
GetName( Void ) Get the node name.
|
| ACharConstPtr |
GetNamespaceURI( Void ) Get the namespace URI.
|
| SFXXMLNodePtr |
GetNextSibling( Void ) Get the next sibling node.
|
| ACharConstPtr |
GetNodeName( Void ) Get the node name.
|
| NodeType |
GetNodeType( Void ) Get the node type.
|
| SFXXMLNodePtr |
GetParentNode( Void ) Get the parent node.
|
| ACharConstPtr |
GetPrefix( Void ) Get the prefix.
|
| SFXXMLNodePtr |
GetPreviousSibling( Void ) Get the previous sibling node.
|
| Bool |
HasAttribute(
SFXAnsiStringConstRef name
) Check whether the Attribute node with a specified name exists or not.
|
| Bool |
HasAttributes( Void ) Check whether any Attribute nodes exist or not.
|
| Bool |
HasChildNodes( Void ) Check wheteher this node has any child nodes or not.
|
| SFCError |
InsertBefore(
SFXXMLNodeConstPtr newchild
, SFXXMLNodeConstPtr refchild
) Insert a specified node.
|
| Void |
RemoveAttribute(
SFXAnsiStringConstRef name
) Remove the Attribute node by name.
|
| SFXXMLAttributePtr |
RemoveAttributeNode(
SFXXMLAttributePtr oldAttr
) Remove the Attribute node from the this node.
|
| SFCError |
RemoveChild(
SFXXMLNodeConstPtr oldchild
) Remove a specified child node including its descendant nodes.
|
| SFCError |
ReplaceChild(
SFXXMLNodeConstPtr newchild
, SFXXMLNodeConstPtr oldchild
) Replace a specified child node.
|
| Void |
SetAttribute(
SFXAnsiStringConstRef name
, ACharConstPtr value
) Set the attribute value.
|
| SFCError |
SetAttributeNode(
SFXXMLAttributePtr newAttr
) Set the Attribute node to this node.
|
| ACharConstPtr |
GetNodeValue( Void )
(inherits from SFXXMLNode)
Get the node value.
|
| SFXAnsiString |
GetText( Void )
(inherits from SFXXMLNode)
Get the node text.
|
| Bool |
IsSameNode(
SFXXMLNodeConstPtr other
)
(inherits from SFXXMLNode)
Check whether this node is the same as a specified one or not.
|
| Void |
SetNodeValue(
ACharConstPtr value
)
(inherits from SFXXMLNode)
Set the node value.
|
| SFCError |
SetText(
SFXAnsiStringConstRef text
)
(inherits from SFXXMLNode)
Set the node text.
|
| Types |
|---|
|
DOMNamedNodeMap
(inherits from SFXXMLNode)
Class to manage the DOM nodes by name
|
|
DOMNodeList
(inherits from SFXXMLNode)
Class to manage the DOM nodes by list
|
|
NodeType
(inherits from SFXXMLNode)
SFXXMLNode::NodeType is an enumeration type of NodeType values defined in the W3C DOM Level 1 Specification.
Document Object Model (DOM) Level 1 Specification )
|
[ public, explicit ]
SFXXMLElement(
SFXXMLDocumentPtr owner // root node of the DOM tree
SFXAnsiStringConstRef name // name of the Element node
);
[ public, explicit ]
SFXXMLElement(
SFXXMLDocumentPtr owner // root node of the DOM tree
SFXAnsiStringConstRef name // name of the Element node
SFXAnsiStringConstRef namespaceURI // namespace URI of the Element node
);
[ public, explicit ]
SFXXMLElement(
SFXXMLElementConstRef other // Element node
Bool deep = false // whether or not to copy the child nodes recursively
);
[ public, virtual ] virtual ~SFXXMLElement(Void);
[ public, virtual ] SFCError AppendChild( SFXXMLNodeConstPtr newchild // child node to append );
The "newchild" node is appended as the last child node to this node without copying it.
If the "newchild" node belongs to a DOM tree, it will be removed from that tree.
[ public, virtual ] SFCError CloneNode( SFXXMLNodeHandle clonenode // target node where to copy this node(Handle type) Bool deep // whether or not to copy the child nodes recursively );
Specify the target node where to copy this node.
If true is set to this argument, copy the child nodes recursively.
Otherwise, copy only this node and its Attribute nodes.
[ public, virtual, const ] Bool EqualNode( SFXXMLNodeConstPtr arg // specified node );
[ public, const ] ACharConstPtr GetAttribute( SFXAnsiStringConstRef name // name of attribute to be retrieved );
Qualified name and namespace URI can be specified as attribute name.
null is returned if this node has no attribute value.
The attribute value can be obtained by qualified name and namespace URI
// get "xmlns:dt" attribute value
SFXAnsiString atti = boot->GetAttribute("xmlns:dt");
SFXXMLElement::GetAttributes | SFXXMLElement::GetAttributeNode | SFXXMLElement::SetAttribute | SFXXMLElement::SetAttributeNode | SFXXMLElement::HasAttribute | SFXXMLElement::HasAttributes | SFXXMLElement::RemoveAttribute | SFXXMLElement::RemoveAttributeNode
[ public, const ] SFXXMLAttributePtr GetAttributeNode( SFXAnsiStringConstRef name // name of the Attribute node to get );
Qualified name and namespace URI can be specified for the Attribute name.
Return the Attribute node with a specified name. Return null if no Attribute node with this name is found.
The Attribute node can be correctly obtained by specifying the qualified name and namespace URI.
// get "xmlns:dt" Attribute node
SFXXMLAttributePtr atti = boot->GetAttributeNode("xmlns:dt");
SFXXMLElement::GetAttribute | SFXXMLElement::GetAttributeNode | SFXXMLElement::SetAttribute | SFXXMLElement::SetAttributeNode | SFXXMLElement::HasAttribute | SFXXMLElement::HasAttributes | SFXXMLElement::RemoveAttribute | SFXXMLElement::RemoveAttributeNode
[ public, const ] DOMNamedNodeMapPtr GetAttributes(Void);
Return the pointer to the Attribute nodes of the SFXXMLNode::DOMNamedNodeMap if any. Return null if not.
// check whether this Element node has any Attribute nodes or not if (SFXXMLElementPtr(child)->HasAttributes()) { // get all the Attribute nodes of this Element node SFXXMLNode::DOMNamedNodeMapPtr attr = SFXXMLElementPtr(child)->GetAttributes(); if (attr) { for (int i = 0; i < attr->GetLength(); i++) { SFXXMLNodePtr item = attr->Item(i); if (item) { if(item->GetNodeType() == SFXXMLNode::ATTRIBUTE_NODE); ... } } } }
SFXXMLNode::DOMNamedNodeMap | SFXXMLElement::GetAttribute | SFXXMLElement::SetAttribute | SFXXMLElement::SetAttributeNode | SFXXMLElement::HasAttribute | SFXXMLElement::HasAttributes | SFXXMLElement::GetAttributeNode | SFXXMLElement::RemoveAttribute | SFXXMLElement::RemoveAttributeNode
[ public, virtual, const ] DOMNodeListPtr GetChildNodes(Void);
Return the pointer to the SFXXMLNode::DOMNodeList instance that contains all child nodes of this node.
![]() |
Note |
|---|---|
| Each element of SFXXMLNode::DOMNodeList is of the "pointer to the SFXXMLNode" type. | |
//get element node by tag name SFXXMLNode::DOMNodeListPtr list = root->GetElementsByTagName("BOOK"); if (list) { // get the enumerator SFXXMLNode::DOMNodeList::Enumerator enumer = list->GetFirstEnumerator(); while (enumer.HasNext()) { // get each element node SFXXMLElementPtr elem = static_cast<SFXXMLElementPtr>(enumer.GetNext()); // get all child nodes of each element node SFXXMLNode::DOMNodeListPtr nodeList = elem->GetChildNodes(); // get enumrator of child nodes SFXXMLNode::DOMNodeList::Enumerator childiter = nodeList->GetFirstEnumerator(); while (childiter.HasNext()) { SFXXMLElementPtr child = static_cast<SFXXMLElementPtr>(childiter.GetNext()); TRACE("child name: %s", child->GetName()); // display name of each child node TRACE("child text: %s", child->GetText().GetCString()); // display child node string content } } }
SFXXMLNode::DOMNodeList | SFXXMLNode::GetChildNodes| SFXXMLNode
[ public, const ]
DOMNodeListPtr GetElementsByTagName(
SFXAnsiStringConstRef name // tag name
);Return all the Element nodes that match a specified tag name as the pointer to the SFXXMLNode::DOMNodeList instance.
[ public, virtual, const ] SFXXMLNodePtr GetFirstChild(Void);
Return the first child node of this node. Return null if this node has no child.
[ public, virtual, const ] SFXXMLNodePtr GetLastChild(Void);
Return the last child node of this node. Return null if this node has no child.
[ public, const ] ACharConstPtr GetLocalName(Void);
Return the local name of this node.
When the name set to this node is qualified name, it is a pair of namespace prefix and local name.
![]() |
Note |
|---|---|
| The name of the Element node is the element name of the XML document. | |
[ public, const ] ACharConstPtr GetName(Void);
Same as the SFXXMLElement::GetNodeName function.
![]() |
Note |
|---|---|
| The name of the Element node is the element name of the XML document. | |
![]() |
Note |
|---|---|
| When the namespace is set, the qualified name(namespace prefix and local name) is returned. | |
<?xml version="1.0" encoding="Shift_JIS"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
version="1.0">
<xsl:output encoding="Shift_JIS" method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">
<html>
<head>
<title>words</title>
</head>
<body bgcolor="#CCFFFF">
<center>
<table border="0">
<xsl:apply-templates select=".//def"/>
</table>
</center>
</body>
</html>
</xsl:template>
<xsl:template match="def">
<tr><td><b><xsl:apply-templates/></b></td></tr>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
// get Element node
SFXXMLElementPtr stylesheet = document.GetDocumentElement();
TRACE("Element's name = %s", stylesheet->GetName()); // name as qualified name = xsl:stylesheet
TRACE("Element's localname = %s", stylesheet->GetLocalName()); // local name = stylesheet
TRACE("Element's prefix = %s", stylesheet->GetPrefix()); // prefix = xsl
TRACE("Element's uri = %s", stylesheet->GetNamespaceURI()); // namespace URI = http://www.w3.org/1999/XSL/Transform
SFXXMLElement::GetLocalName | SFXXMLElement::GetNodeName | SFXXMLElement::GetPrefix | SFXXMLElement::GetNamespaceURI
[ public, const ] ACharConstPtr GetNamespaceURI(Void);
Return the namespace URI of this node if set. Otherwise, return null.
[ public, virtual, const ] SFXXMLNodePtr GetNextSibling(Void);
Return the next sibling node of this node. If this node has no next sibling node, null is returned.
SFXXMLDOMParser parser; // parse XML document by DOM method // get root node of DOM tree SFXXMLDocumentPtr root = parser.GetDocument(); // get first child of root node SFXXMLNodePtr node = root->GetFirstChild(); SFXXMLElementPtr elem = static_cast<SFXXMLElementPtr>(node); // convert into Element pointer type SFXXMLNodePtr child = elem->GetFirstChild(); // get first child node SFXXMLNodePtr author = child->GetNextSibling(); // get next sibling node
SFXXMLElement::GetPreviousSibling | SFXXMLNode::GetNextSibling| SFXXMLNode::GetPreviousSibling | SFXXMLNode
[ public, virtual, const ] ACharConstPtr GetNodeName(Void);
Same as the SFXXMLElement::GetName function.
![]() |
Note |
|---|---|
| The name of the Element node is the element name of the XML document. | |
![]() |
Note |
|---|---|
| When the namespace is set, the qualified name(namespace prefix and local name) is returned. | |
SFXXMLElement::GetName | SFXXMLNode::GetNodeName | SFXXMLNode
[ public, virtual, const ] NodeType GetNodeType(Void);
Return ELEMENT_NODE.
[ public, virtual, const ] SFXXMLNodePtr GetParentNode(Void);
Return the parent node of this node. Return null if this node has no parent.
[ public, const ] ACharConstPtr GetPrefix(Void);
Return the prefix of this node if set. Otherwise return null.
[ public, virtual, const ] SFXXMLNodePtr GetPreviousSibling(Void);
Return the previous sibling node of this node. If this node has no previous sibling node, null is returned.
SFXXMLElement::GetNextSibling | SFXXMLNode::GetPreviousSibling | SFXXMLNode::GetNextSibling | SFXXMLNode
[ public, const ] Bool HasAttribute( SFXAnsiStringConstRef name // attribute name );
// check whether the Attribute node with name of "isdn" exists or not
if(book->HasAttribute("isdn") == false){
.....
}
SFXXMLElement::HasAttributes | SFXXMLElement::SetAttribute | SFXXMLElement::SetAttributeNode | SFXXMLElement::SetAttribute | SFXXMLElement::SetAttributeNode | SFXXMLElement::GetAttribute | SFXXMLElement::GetAttributes | SFXXMLElement::RemoveAttribute | SFXXMLElement::RemoveAttributeNode
[ public, const ] Bool HasAttributes(Void);
// check whether any Attribute nodes exist or not
if(book->HasAttributes() == false){
.....
}
SFXXMLElement::HasAttribute | SFXXMLElement::GetAttribute | SFXXMLElement::GetAttributes | SFXXMLElement::RemoveAttribute | SFXXMLElement::RemoveAttributeNode
[ public, virtual, const ] Bool HasChildNodes(Void);
[ public, virtual ] SFCError InsertBefore( SFXXMLNodeConstPtr newchild // node to insert SFXXMLNodeConstPtr refchild // newchild node is inserted before refchild node );
Insert the newchild node before the refchild node. If the refchild argument is specified as null, append the newchild node as the last child node.
When the newchild node is the DocumentFragment node, all the child nodes of the newchild node are inserted in the same order before the refchild node.
When the newchild node has already existed in the DOM tree, it is removed before insertion.
// create Element node SFXXMLElementPtr isbn = document.CreateElement("ISBN"); // add Text node to Element node isbn->AppendChild(SFXXMLNodePtr(document.CreateTextNode("4-7741-1616-5"))); // insert Element node book->InsertBefore(SFXXMLNodePtr(isbn), book->GetFirstChild());
[ public ] Void RemoveAttribute( SFXAnsiStringConstRef name // attribute name to remove );
If the Attribute node that match a specified name does not exist, this function is invalid .
![]() |
Note |
|---|---|
| Qualified name(namespace prefix and local name) can be specified. | |
// remove "dt:dt" Attribute node of "date" Element node
date->RemoveAttribute("dt:dt");
SFXXMLElement::GetAttribute | SFXXMLElement::SetAttributeNode | SFXXMLElement::GetAttributeNode | SFXXMLElement::SetAttribute | SFXXMLElement::RemoveAttributeNode
[ public ] SFXXMLAttributePtr RemoveAttributeNode( SFXXMLAttributePtr oldAttr // Attribute node to remove );
Return the removed Attribute node (SFXXMLAttribute).
// get "dt:dt" Attrubite node SFXXMLAttributePtr atti = book->GetAttributeNode("dt:dt"); // remove this Attribite node from DOMNamedNodeMap book->RemoveAttributeNode(atti); // delete this node delete atti;
SFXXMLAttribute | SFXXMLElement::GetAttribute | SFXXMLElement::SetAttributeNode | SFXXMLElement::GetAttributeNode | SFXXMLElement::SetAttribute | SFXXMLElement::RemoveAttribute
[ public, virtual ] SFCError RemoveChild( SFXXMLNodeConstPtr oldchild // child node to remove );
[ public, virtual ] SFCError ReplaceChild( SFXXMLNodeConstPtr newchild // new child node to replace with SFXXMLNodeConstPtr oldchild // old child node to be replaced );
// create the name node SFXXMLElementPtr name = document.CreateElement("NAME"); // set a text to the name node name->AppendChild(SFXXMLNodePtr(document.CreateTextNode("Cosmos"))); // replace the first child of book node with the name node book->ReplaceChild(name, book->GetFirstChild());
[ public ] Void SetAttribute( SFXAnsiStringConstRef name // attribute name to set ACharConstPtr value // attribute value to set );
If the attribute with a specified name already exists, new value is set to this attribute.
![]() |
Note |
|---|---|
| Qualified name(namespace prefix and local name) can be specified. | |
![]() |
Method to set the attribute value including an entity reference |
|---|---|
To set the attribute value including entity reference, specify the Attribute node(SFXXMLAttribute) that has any Text nodes(SFXXMLText) and a SFXXMLEntityReference node for an argument of the SFXXMLElement::SetAttributeNode function. | |
SFXXMLElement::SetAttributeNode | SFXXMLElement::GetAttribute | SFXXMLElement::GetAttributeNode | SFXXMLElement::HasAttribute | SFXXMLElement::HasAttributes | SFXXMLElement::RemoveAttribute | SFXXMLElement::RemoveAttributeNode
[ public ] SFCError SetAttributeNode( SFXXMLAttributePtr newAttr // Attribute node to set );
If the Attribute node with the same name of specified Attribute node exists, it will be deleted and replaced with a specified Attribute node.
// create isdn attribute (attribute value is set, too) SFXXMLAttributePtr atti = document.CreateAttribute("isdn","4-7741-1616-5"); // add attribute to BOOK element book->SetAttributeNode(atti);
|
Copyright (C) 2002 - 2009 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|