本文整理汇总了C++中DOM_Node::getNodeValue方法的典型用法代码示例。如果您正苦于以下问题:C++ DOM_Node::getNodeValue方法的具体用法?C++ DOM_Node::getNodeValue怎么用?C++ DOM_Node::getNodeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOM_Node
的用法示例。
在下文中一共展示了DOM_Node::getNodeValue方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getValue
//======================================================================
//======================================================================
char* XMLDocument::getValue(DOM_Node currNode, char* path, DataTypeAttribute** dtAttributes)
{
if (mDoc == NULL)
return NULL;
if (path == NULL)
return NULL;
DOM_Node child = getNode(currNode, path, dtAttributes);
if (child == NULL)
return NULL;
child = child.getFirstChild();
if (child == NULL)
return NULL;
// If siblings exist, this is not an leaf, but a branch
DOM_Node sib = child.getNextSibling();
if (sib != NULL)
return NULL;
if (child.getNodeType() != DOM_Node::TEXT_NODE && child.getNodeType() != DOM_Node::CDATA_SECTION_NODE)
return NULL;
return child.getNodeValue().transcode();
}
示例2: traverseTextNode
/**
* Utility method for traversing a text node that we know
* a-priori to be on a left or right boundary of the range.
* This method does not properly handle text nodes that contain
* both the start and end points of the range.
*
*/
DOM_Node RangeImpl::traverseTextNode( DOM_Node n, bool isLeft, int how )
{
DOMString txtValue = n.getNodeValue();
DOMString newNodeValue;
DOMString oldNodeValue;
if ( isLeft )
{
int offset = getStartOffset();
newNodeValue = txtValue.substringData( offset , fStartContainer.getNodeValue().length()-offset);
oldNodeValue = txtValue.substringData( 0, offset );
}
else
{
int offset = getEndOffset();
newNodeValue = txtValue.substringData( 0, offset );
oldNodeValue = txtValue.substringData( offset , fEndContainer.getNodeValue().length()-offset );
}
if ( how != CLONE_CONTENTS )
n.setNodeValue( oldNodeValue );
if ( how==DELETE_CONTENTS )
return null;
DOM_Node newNode = n.cloneNode( false );
newNode.setNodeValue( newNodeValue );
return newNode;
}
示例3: doAttributesMatch
//======================================================================
//======================================================================
bool XMLDocument::doAttributesMatch(DOM_Node currNode, DataTypeAttribute** dtAttributes)
{
DOM_NamedNodeMap nnodeMap = currNode.getAttributes();
int len = nnodeMap.getLength();
int a = 0;
DataTypeAttribute* dtAttribute;
while ((dtAttribute = (DataTypeAttribute*)dtAttributes[a++]) != (DataTypeAttribute*)NULL)
{
bool isFound = false;
for (int i = 0; i < len && !isFound; i++)
{
DOM_Node attNode = nnodeMap.item(i);
char* tmp = attNode.getNodeName().transcode();
char* tmp1 = attNode.getNodeValue().transcode();
if (strcmp(dtAttribute->getName(), tmp) == 0 &&
strcmp(dtAttribute->getValue(), tmp1) == 0)
{
isFound = true;
}
delete[] tmp;
delete[] tmp1;
}
if (!isFound)
return false;
}
return true;
}
示例4: clone
DOM_Node XMLDocument::clone(DOM_Node currNode)
{
switch (currNode.getNodeType())
{
case DOM_Node::ELEMENT_NODE:
{
DOM_Element elem = mDoc.createElement(currNode.getNodeName());
DOM_NamedNodeMap nnodeMap = currNode.getAttributes();
for (unsigned int i = 0; i < nnodeMap.getLength(); i++)
{
DOM_Node attNode = nnodeMap.item(i);
elem.setAttribute(attNode.getNodeName(), attNode.getNodeValue());
}
DOM_Node child = currNode.getFirstChild();
while (child != NULL)
{
DOM_Node cNode = clone(child);
if (cNode != NULL)
elem.appendChild(cNode);
child = child.getNextSibling();
}
return (DOM_Node)elem;
}
case DOM_Node::TEXT_NODE:
{
DOM_Text childText = mDoc.createTextNode(currNode.getNodeValue());
return (DOM_Node)childText;
}
case DOM_Node::CDATA_SECTION_NODE:
{
DOM_CDATASection childCData = mDoc.createCDATASection(currNode.getNodeValue());
return (DOM_Node)childCData;
}
default:
{
return NULL_DOM_Node;
}
}
}
示例5: setValue
//======================================================================
//======================================================================
bool XMLDocument::setValue(DOM_Node currNode, char* path, DataTypeAttribute** dtAttributes, char* value)
{
if (mDoc == NULL)
return false;
if (path == NULL)
return false;
DOM_Node child = getNode(currNode, path, dtAttributes);
if (child == NULL)
return false;
DOM_Node parent = child.getParentNode();
if (parent == NULL)
return false;
DOM_Node grandChild = child.getFirstChild();
short nType = DOM_Node::TEXT_NODE;
if (grandChild != NULL)
{
nType = grandChild.getNodeType();
if (nType != DOM_Node::TEXT_NODE && nType != DOM_Node::CDATA_SECTION_NODE)
return false;
}
char* childName = child.getNodeName().transcode();
DOM_NamedNodeMap nnodeMap = child.getAttributes();
parent.removeChild(child);
DOM_Element childElement = mDoc.createElement(childName);
delete[] childName;
for (unsigned int i = 0; i < nnodeMap.getLength(); i++)
{
DOM_Node attNode = nnodeMap.item(i);
childElement.setAttribute(attNode.getNodeName(), attNode.getNodeValue());
}
if (nType == DOM_Node::TEXT_NODE)
{
DOM_Text childText = mDoc.createTextNode((value == NULL)?"":value);
childElement.appendChild(childText);
}
else
{
DOM_CDATASection childCData = mDoc.createCDATASection((value == NULL)?"":value);
childElement.appendChild(childCData);
}
parent.appendChild(childElement);
return true;
}
示例6: traverseSameContainer
/**
* Visits the nodes selected by this range when we know
* a-priori that the start and end containers are the same.
*
*/
DOM_DocumentFragment RangeImpl::traverseSameContainer( int how )
{
DOM_DocumentFragment frag = null;
if ( how!=DELETE_CONTENTS)
frag = fDocument.createDocumentFragment();
// If selection is empty, just return the fragment
if ( fStartOffset==fEndOffset )
return frag;
DOM_Node current = fStartContainer;
DOM_Node cloneCurrent = null;
// Text node needs special case handling
if ( fStartContainer.getNodeType()== DOM_Node::TEXT_NODE )
{
cloneCurrent = fStartContainer.cloneNode(false);
cloneCurrent.setNodeValue(
cloneCurrent.getNodeValue().substringData(fStartOffset, fEndOffset - fStartOffset));
// set the original text node to its new value
if ( how != CLONE_CONTENTS )
((DOM_Text &)fStartContainer).deleteData(fStartOffset, fEndOffset-fStartOffset);
if ( how != DELETE_CONTENTS)
frag.appendChild(cloneCurrent);
}
else {
// Copy nodes between the start/end offsets.
DOM_Node n = getSelectedNode( fStartContainer, fStartOffset );
int cnt = fEndOffset - fStartOffset;
while( cnt > 0 )
{
DOM_Node sibling = n.getNextSibling();
DOM_Node xferNode = traverseFullySelected( n, how );
if ( frag!=null )
frag.appendChild( xferNode );
--cnt;
n = sibling;
}
}
// Nothing is partially selected, so collapse to start point
if ( how != CLONE_CONTENTS )
collapse(true);
return frag;
}
示例7: toString
DOMString RangeImpl::toString() const
{
if( fDetached) {
throw DOM_DOMException(
DOM_DOMException::INVALID_STATE_ERR, null);
}
DOM_Node node = fStartContainer;
DOM_Node stopNode = fEndContainer;
DOMString tempString;
if ( (fStartContainer.getNodeType() == DOM_Node::TEXT_NODE)
|| (fStartContainer.getNodeType() == DOM_Node::CDATA_SECTION_NODE) ) {
if (fStartContainer == fEndContainer) {
tempString.appendData(fStartContainer.getNodeValue().substringData(fStartOffset, fEndOffset-fStartOffset));
return tempString;
} else {
int length = fStartContainer.getNodeValue().length();
tempString.appendData(fStartContainer.getNodeValue().substringData(fStartOffset, length - fStartOffset));
node = nextNode(node, true);
}
} else { //fStartContainer is not a TextNode
node=node.getFirstChild();
if (fStartOffset>0) { //find a first node within a range, specified by fStartOffset
unsigned int counter = 0;
while (counter<fStartOffset && node!=null) {
node=node.getNextSibling();
counter++;
}
}
if (node == null) {
node = nextNode(fStartContainer,false);
}
}
if ( fEndContainer.getNodeType()!= DOM_Node::TEXT_NODE &&
fEndContainer.getNodeType()!= DOM_Node::CDATA_SECTION_NODE ) {
int i=fEndOffset;
stopNode = fEndContainer.getFirstChild();
while( i>0 && stopNode!=null ) {
--i;
stopNode = stopNode.getNextSibling();
}
if ( stopNode == null )
stopNode = nextNode( fEndContainer, false );
}
while (node != stopNode) { //look into all kids of the Range
if (node == null) break;
if (node.getNodeType() == DOM_Node::TEXT_NODE
|| node.getNodeType() == DOM_Node::CDATA_SECTION_NODE) {
tempString.appendData(node.getNodeValue());
}
node = nextNode(node, true);
}
if (fEndContainer.getNodeType() == DOM_Node::TEXT_NODE
|| fEndContainer.getNodeType() == DOM_Node::CDATA_SECTION_NODE) {
tempString.appendData(fEndContainer.getNodeValue().substringData(0,fEndOffset));
}
return tempString;
}
示例8: switch
// ---------------------------------------------------------------------------
// ostream << DOM_Node
//
// Stream out a DOM node, and, recursively, all of its children. This
// function is the heart of writing a DOM tree out as XML source. Give it
// a document node and it will do the whole thing.
// ---------------------------------------------------------------------------
ostream& operator<<(ostream& target, DOM_Node& toWrite)
{
// Get the name and value out for convenience
DOMString nodeName = toWrite.getNodeName();
DOMString nodeValue = toWrite.getNodeValue();
unsigned long lent = nodeValue.length();
switch (toWrite.getNodeType())
{
case DOM_Node::TEXT_NODE:
{
gFormatter->formatBuf(nodeValue.rawBuffer(),
lent, XMLFormatter::CharEscapes);
break;
}
case DOM_Node::PROCESSING_INSTRUCTION_NODE :
{
*gFormatter << XMLFormatter::NoEscapes << gStartPI << nodeName;
if (lent > 0)
{
*gFormatter << chSpace << nodeValue;
}
*gFormatter << XMLFormatter::NoEscapes << gEndPI;
break;
}
case DOM_Node::DOCUMENT_NODE :
{
DOM_Node child = toWrite.getFirstChild();
while( child != 0)
{
target << child;
// add linefeed in requested output encoding
*gFormatter << chLF;
target << flush;
child = child.getNextSibling();
}
break;
}
case DOM_Node::ELEMENT_NODE :
{
// The name has to be representable without any escapes
*gFormatter << XMLFormatter::NoEscapes
<< chOpenAngle << nodeName;
// Output the element start tag.
// Output any attributes on this element
DOM_NamedNodeMap attributes = toWrite.getAttributes();
int attrCount = attributes.getLength();
for (int i = 0; i < attrCount; i++)
{
DOM_Node attribute = attributes.item(i);
//
// Again the name has to be completely representable. But the
// attribute can have refs and requires the attribute style
// escaping.
//
*gFormatter << XMLFormatter::NoEscapes
<< chSpace << attribute.getNodeName()
<< chEqual << chDoubleQuote
<< XMLFormatter::AttrEscapes
<< attribute.getNodeValue()
<< XMLFormatter::NoEscapes
<< chDoubleQuote;
}
//
// Test for the presence of children, which includes both
// text content and nested elements.
//
DOM_Node child = toWrite.getFirstChild();
if (child != 0)
{
// There are children. Close start-tag, and output children.
// No escapes are legal here
*gFormatter << XMLFormatter::NoEscapes << chCloseAngle;
while( child != 0)
{
target << child;
child = child.getNextSibling();
}
//
// Done with children. Output the end tag.
//.........这里部分代码省略.........
示例9: encode
char* XMLDocument::encode(DOM_Node currNode)
{
string result = "";
if (currNode == NULL)
return strclone((char*)result.c_str());
switch (currNode.getNodeType())
{
case DOM_Node::ELEMENT_NODE:
{
char* tmp = currNode.getNodeName().transcode();
result += (string)"<" + (string)tmp;
delete[] tmp;
DOM_NamedNodeMap nnodeMap = currNode.getAttributes();
for (unsigned int i = 0; i < nnodeMap.getLength(); i++)
{
DOM_Node attNode = nnodeMap.item(i);
tmp = attNode.getNodeName().transcode();
char* tmp1 = attNode.getNodeValue().transcode();
result += (string)" " + (string)tmp + (string)"=\"" + (string)tmp1 + (string)"\"";
delete[] tmp;
delete[] tmp1;
}
result += (string)">";
DOM_Node child = currNode.getFirstChild();
while (child != NULL)
{
char *childStr = encode(child);
result += childStr;
delete[] childStr;
child = child.getNextSibling();
}
tmp = currNode.getNodeName().transcode();
result += (string)"</" + (string)tmp + ">";
delete[] tmp;
return strclone((char*)result.c_str());
}
case DOM_Node::TEXT_NODE:
case DOM_Node::CDATA_SECTION_NODE:
{
static char reservedChars[] = "<>&'\"";
char *str = currNode.getNodeValue().transcode();
bool bSpecialChars = false;
int len = strlen(str);
for (int i = 0; i < len; i++)
{
if (strchr(reservedChars, str[i]) != NULL)
{
bSpecialChars = true;
break;
}
}
if (bSpecialChars == false)
result += (string)str;
else
result += (string)"<![CDATA[" + (string)str + (string)"]]>";
delete[] str;
return strclone((char*)result.c_str());
}
default:
{
return strclone((char*)result.c_str());
}
}
}