本文整理汇总了C++中NamedNodeMap类的典型用法代码示例。如果您正苦于以下问题:C++ NamedNodeMap类的具体用法?C++ NamedNodeMap怎么用?C++ NamedNodeMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NamedNodeMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getAttributeItem
void NamedNodeMap::setAttributes(const NamedNodeMap& other)
{
// clone all attributes in the other map, but attach to our element
if (!m_element)
return;
// If assigning the map changes the id attribute, we need to call
// updateId.
Attribute* oldId = getAttributeItem(m_element->idAttributeName());
Attribute* newId = other.getAttributeItem(m_element->idAttributeName());
if (oldId || newId)
m_element->updateId(oldId ? oldId->value() : nullAtom, newId ? newId->value() : nullAtom);
clearAttributes();
unsigned newLength = other.length();
m_attributes.resize(newLength);
for (unsigned i = 0; i < newLength; i++)
m_attributes[i] = other.m_attributes[i]->clone();
// FIXME: This is wasteful. The class list could be preserved on a copy, and we
// wouldn't have to waste time reparsing the attribute.
// The derived class, HTMLNamedNodeMap, which manages a parsed class list for the CLASS attribute,
// will update its member variable when parse attribute is called.
for (unsigned i = 0; i < newLength; i++)
m_element->attributeChanged(m_attributes[i].get(), true);
}
示例2: runTest
/*
* Runs the test case.
*/
void runTest()
{
Document doc;
NodeList elementList;
Element firstNode;
Node testNode;
NamedNodeMap attributes;
Attr domesticAttr;
Attr setAttr;
Node setNode;
doc = (Document) baseT::load("staff", true);
elementList = doc.getElementsByTagName(SA::construct_from_utf8("address"));
firstNode = (Element) elementList.item(0);
domesticAttr = doc.createAttribute(SA::construct_from_utf8("domestic"));
domesticAttr.setValue(SA::construct_from_utf8("Yes"));
setAttr = firstNode.setAttributeNode(domesticAttr);
elementList = doc.getElementsByTagName(SA::construct_from_utf8("address"));
testNode = elementList.item(2);
attributes = testNode.getAttributes();
{
boolean success = false;
try {
setNode = attributes.setNamedItem(domesticAttr);
} catch (const DOMException& ex) {
success = (ex.code() == DOMException::INUSE_ATTRIBUTE_ERR);
}
assertTrue(success);
}
}
示例3: arg
Value FunLang::evaluate() const
{
String lang = arg(0)->evaluate().toString();
Attribute* languageAttribute = 0;
Node* node = evaluationContext().node.get();
while (node) {
NamedNodeMap* attrs = node->attributes();
if (attrs)
languageAttribute = attrs->getAttributeItem(XMLNames::langAttr);
if (languageAttribute)
break;
node = node->parentNode();
}
if (!languageAttribute)
return BOOL_TO_VALUE_CAST false;
String langValue = languageAttribute->value();
while (true) {
if (equalIgnoringCase(langValue, lang))
return BOOL_TO_VALUE_CAST true;
// Remove suffixes one by one.
size_t index = langValue.reverseFind('-');
if (index == notFound)
break;
langValue = langValue.left(index);
}
return BOOL_TO_VALUE_CAST false;
}
示例4:
Node*
Element::_getElementById (const DOMString& id)
{
for (size_t i = 0; i < _children.length(); i++) {
NamedNodeMap attrs = _children.item(i)->attributes();
for (size_t h = 0; h < attrs.length(); h++) {
Attr* attr = (Attr*) attrs.item(h);
if (attr->_isId) {
if (attr->value() == id) {
return _children.item(i);
}
}
}
}
for (size_t i = 0; i < _children.length(); i++) {
Node* element = _children.item(i)->_getElementById(id);
if (element) {
return element;
}
}
return NULL;
}
示例5: runTest
/*
* Runs the test case.
*/
void runTest()
{
Document doc1;
Document doc2;
NodeList elementList;
Node testAddress;
NamedNodeMap attributes;
Node newAttribute;
String strong;
Node setNode;
doc1 = (Document) baseT::load("hc_staff", true);
doc2 = (Document) baseT::load("hc_staff", true);
elementList = doc1.getElementsByTagName(SA::construct_from_utf8("acronym"));
testAddress = elementList.item(2);
newAttribute = doc2.createAttribute(SA::construct_from_utf8("newAttribute"));
attributes = testAddress.getAttributes();
{
boolean success = false;
try {
setNode = attributes.setNamedItem(newAttribute);
} catch (const DOMException& ex) {
success = (ex.code() == DOMException::WRONG_DOCUMENT_ERR);
}
assertTrue(success);
}
}
示例6: imageToMarkup
static String imageToMarkup(const String& url, Element* element)
{
StringBuilder markup;
markup.append("<img src=\"");
markup.append(url);
markup.append("\"");
// Copy over attributes. If we are dragging an image, we expect things like
// the id to be copied as well.
NamedNodeMap* attrs = element->attributes();
unsigned length = attrs->length();
for (unsigned i = 0; i < length; ++i) {
Attribute* attr = attrs->attributeItem(i);
if (attr->localName() == "src")
continue;
markup.append(" ");
markup.append(attr->localName());
markup.append("=\"");
String escapedAttr = attr->value();
escapedAttr.replace("\"", """);
markup.append(escapedAttr);
markup.append("\"");
}
markup.append("/>");
return markup.toString();
}
示例7: runTest
/*
* Runs the test case.
*/
void runTest()
{
Document doc;
NodeList acronymList;
Node testNode;
NamedNodeMap attributes;
Attr titleAttr;
String value;
Node textNode;
Node retval;
Node lastChild;
Document otherDoc;
doc = (Document) baseT::load("hc_staff", true);
otherDoc = (Document) baseT::load("hc_staff", true);
acronymList = doc.getElementsByTagName(SA::construct_from_utf8("acronym"));
testNode = acronymList.item(3);
attributes = testNode.getAttributes();
titleAttr = (Attr) attributes.getNamedItem(SA::construct_from_utf8("title"));
textNode = otherDoc.createTextNode(SA::construct_from_utf8("terday"));
{
boolean success = false;
try {
retval = titleAttr.appendChild(textNode);
} catch (const DOMException& ex) {
success = (ex.code() == DOMException::WRONG_DOCUMENT_ERR);
}
assertTrue(success);
}
}
示例8: jsNamedNodeMapLength
JSValue jsNamedNodeMapLength(ExecState* exec, JSValue slotBase, const Identifier&)
{
JSNamedNodeMap* castedThis = static_cast<JSNamedNodeMap*>(asObject(slotBase));
UNUSED_PARAM(exec);
NamedNodeMap* imp = static_cast<NamedNodeMap*>(castedThis->impl());
JSValue result = jsNumber(imp->length());
return result;
}
示例9: appendOpenTag
void MarkupAccumulator::appendElement(StringBuilder& out, Element* element, Namespaces* namespaces)
{
appendOpenTag(out, element, namespaces);
NamedNodeMap* attributes = element->attributes();
unsigned length = attributes->length();
for (unsigned int i = 0; i < length; i++)
appendAttribute(out, element, *attributes->attributeItem(i), namespaces);
appendCloseTag(out, element);
}
示例10: parametersForPlugin
void HTMLEmbedElement::parametersForPlugin(Vector<String>& paramNames, Vector<String>& paramValues)
{
NamedNodeMap* attributes = this->attributes(true);
if (!attributes)
return;
for (unsigned i = 0; i < attributes->length(); ++i) {
Attribute* it = attributes->attributeItem(i);
paramNames.append(it->localName().string());
paramValues.append(it->value().string());
}
}
示例11: getNames
void DatasetDOMStringMap::getNames(Vector<String>& names)
{
NamedNodeMap* attributeMap = m_element->attributes(true);
if (attributeMap) {
unsigned length = attributeMap->length();
for (unsigned i = 0; i < length; i++) {
Attribute* attribute = attributeMap->attributeItem(i);
if (isValidAttributeName(attribute->localName()))
names.append(convertAttributeNameToPropertyName(attribute->localName()));
}
}
}
示例12: mergeAttributesFromTokenIntoElement
void HTMLConstructionSite::mergeAttributesFromTokenIntoElement(AtomicHTMLToken& token, Element* element)
{
if (!token.attributes())
return;
NamedNodeMap* attributes = element->attributes(false);
for (unsigned i = 0; i < token.attributes()->length(); ++i) {
Attribute* attribute = token.attributes()->attributeItem(i);
if (!attributes->getAttributeItem(attribute->name()))
element->setAttribute(attribute->name(), attribute->value());
}
}
示例13: write
void XmlWriter::write(const NodePtr nodeArg)
{
NodePtr node = nodeArg;
indent+=2;
NamedNodeMap attributes = node->getAttributes();
int nrAttrs = attributes.getLength();
//### Start open tag
spaces();
po("<");
pos(node->getNodeName());
if (nrAttrs>0)
po("\n");
//### Attributes
for (int i=0 ; i<nrAttrs ; i++)
{
NodePtr attr = attributes.item(i);
spaces();
pos(attr->getNodeName());
po("=\"");
pos(attr->getNodeValue());
po("\"\n");
}
//### Finish open tag
if (nrAttrs>0)
spaces();
po(">\n");
//### Contents
spaces();
pos(node->getNodeValue());
//### Children
for (NodePtr child = node->getFirstChild() ;
child.get() ;
child=child->getNextSibling())
{
write(child);
}
//### Close tag
spaces();
po("</");
pos(node->getNodeName());
po(">\n");
indent-=2;
}
示例14: contains
bool DatasetDOMStringMap::contains(const String& name)
{
NamedNodeMap* attributeMap = m_element->attributes(true);
if (attributeMap) {
unsigned length = attributeMap->length();
for (unsigned i = 0; i < length; i++) {
Attribute* attribute = attributeMap->attributeItem(i);
if (propertyNameMatchesAttributeName(name, attribute->localName()))
return true;
}
}
return false;
}
示例15: highestVisuallyEquivalentDivBelowRoot
// When inserting a new line, we want to avoid nesting empty divs if we can. Otherwise, when
// pasting, it's easy to have each new line be a div deeper than the previous. E.g., in the case
// below, we want to insert at ^ instead of |.
// <div>foo<div>bar</div>|</div>^
static Element* highestVisuallyEquivalentDivBelowRoot(Element* startBlock)
{
Element* curBlock = startBlock;
// We don't want to return a root node (if it happens to be a div, e.g., in a document fragment) because there are no
// siblings for us to append to.
while (!curBlock->nextSibling() && curBlock->parentElement()->hasTagName(divTag) && curBlock->parentElement()->parentElement()) {
NamedNodeMap* attributes = curBlock->parentElement()->attributes(true);
if (attributes && !attributes->isEmpty())
break;
curBlock = curBlock->parentElement();
}
return curBlock;
}