/*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList acronymList;
     Node testNode;
     NamedNodeMap attributes;
     Attr titleAttr;
     String value;
     Text textNode;
     Node retval;
     Node lastChild;
     doc = (Document) baseT::load("hc_staff", true);
     titleAttr = doc.createAttribute(SA::construct_from_utf8("title"));
     textNode = doc.createTextNode(SA::construct_from_utf8("Yesterday"));
     retval = titleAttr.appendChild(textNode);
     value = titleAttr.getValue();
     baseT::assertEquals("Yesterday", value, __LINE__, __FILE__);
 value = titleAttr.getNodeValue();
     baseT::assertEquals("Yesterday", value, __LINE__, __FILE__);
 value = retval.getNodeValue();
     baseT::assertEquals("Yesterday", value, __LINE__, __FILE__);
 lastChild = titleAttr.getLastChild();
     value = lastChild.getNodeValue();
     baseT::assertEquals("Yesterday", value, __LINE__, __FILE__);
 
  }
void dumpattrs(Node *node)
{
    NamedNodeMap  *attrs;
    Attr          *a;
    uword          i;
    size_t         na;

    oratext   *qname;
    oratext   *namespce;
    oratext   *local;
    oratext   *prefix;
    oratext   *value;

    if (attrs = node->getAttributes())
    {
       cout << "\n    ATTRIBUTES: \n";
       for (na = attrs->getLength(), i = 0; i < na; i++)
       { 
          /* get attr qualified name, local name, namespace, and prefix */

          a = (Attr *)attrs->item(i);

          qname = namespce = local = prefix = value = (oratext*)" ";

          if (a->getQualifiedName() != (oratext*)NULL)
             qname = a->getQualifiedName();

          if (a->getNamespace() != (oratext*)NULL)
             namespce = a->getNamespace();

          if (a->getLocal() != (oratext*)NULL)
             local = a->getLocal();

          if (a->getPrefix() != (oratext*)NULL)
             prefix = a->getPrefix();

          if (a->getValue() != (oratext*)NULL)
             value = a->getValue();

          cout << "      " << (char*)qname << " = " << (char*)value << "\n";
          cout << "      Namespace : " << (char*)namespce << "\n";
          cout << "      Local Name: " << (char*)local << "\n";
          cout << "      Prefix    : " << (char*)prefix << "\n\n";
       }
    }
    cout << "\n";
}
Exemple #3
0
const XMLString& Element::getAttribute(const XMLString& name) const
{
	Attr* pAttr = getAttributeNode(name);
	if (pAttr)
		return pAttr->getValue();
	else
		return EMPTY_STRING;
}
Exemple #4
0
const XMLString& Element::getAttributeNS(const XMLString& namespaceURI, const XMLString& localName) const
{
	Attr* pAttr = getAttributeNodeNS(namespaceURI, localName);
	if (pAttr)
		return pAttr->getValue();
	else
		return EMPTY_STRING;
}
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     NodeList elementList;
     Element testEmployee;
     Attr streetAttr;
     Attr removedAttr;
     String removedValue;
     doc = (Document) baseT::load("hc_staff", true);
     elementList = doc.getElementsByTagName(SA::construct_from_utf8("acronym"));
     testEmployee = (Element) elementList.item(2);
     streetAttr = testEmployee.getAttributeNode(SA::construct_from_utf8("class"));
     removedAttr = testEmployee.removeAttributeNode(streetAttr);
     baseT::assertNotNull(removedAttr, __LINE__, __FILE__);
     removedValue = removedAttr.getValue();
     baseT::assertEquals("No", removedValue, __LINE__, __FILE__);
 
  }
void dumpTree(std::ostream& result, Node node, std::string indent)
{
    while (node) {
        result << indent << node << '\n';
        Element element = interface_cast<Element>(node);
        if (element.getNodeType() == Node::ELEMENT_NODE) {
            ObjectArray<Attr> attrArray = element.getAttributes();
            assert(attrArray);
            for (unsigned int i = 0; i < attrArray.getLength(); ++i) {
                Attr attr = attrArray.getElement(i);
                assert(attr);
                result << indent << "  " << attr.getName() << "=\"" << attr.getValue() << "\"\n";
            }
        }
        if (node.hasChildNodes())
            dumpTree(result, node.getFirstChild(), indent + ((node.getNodeType() == Node::DOCUMENT_NODE) ? "| " : "  "));
        node = node.getNextSibling();
    }
}