List of usage examples for org.w3c.dom Attr getName
public String getName();
From source file:org.adl.samplerte.server.LMSManifestHandler.java
License:asdf
/**************************************************************************** ** //from w w w .ja v a 2s .c o m ** Method: getAttribute() Input: Node theNode - The current node that was * traversed to String the Attribute - The name of the attribute that the * value is desired for. Output: Description: This method ** ** Side Effects: none ** ***************************************************************************/ protected String getAttribute(Node theNode, String theAttribute) { String returnValue = new String(); // grab attributes of the node Attr attrs[] = sortAttributes(theNode.getAttributes()); // now see if the asked for attribute exists and send // back the value Attr attribute; for (int i = 0; i < attrs.length; i++) { attribute = attrs[i]; if (attribute.getName().equals(theAttribute)) { returnValue = attribute.getValue(); break; } } return returnValue; }
From source file:com.marklogic.dom.ElementImpl.java
protected Node cloneNode(Document doc, boolean deep) { Element elem = doc.createElementNS(getNamespaceURI(), getTagName()); elem.setPrefix(getPrefix());/*from ww w. ja va 2 s. c o m*/ for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); if (attr instanceof AttrImpl) { elem.setAttributeNode((Attr) ((AttrImpl) attr).cloneNode(doc, deep)); } else { // ns decl, stored as Java DOM Attr // uri of xmlns is "http://www.w3.org/2000/xmlns/" Attr clonedAttr = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", attr.getName()); clonedAttr.setValue(attr.getValue()); elem.setAttributeNode(clonedAttr); } } if (deep) { // clone children NodeList list = getChildNodes(); for (int i = 0; i < list.getLength(); i++) { NodeImpl n = (NodeImpl) list.item(i); Node c = n.cloneNode(doc, true); elem.appendChild(c); } } return elem; }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
private void addAttributes(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context, NamedNodeMap attributes, SOAPElement soapElement) throws SOAPException { SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild(); String targetNamespace = soapMethodResponseElement.getNamespaceURI(); String prefix = soapMethodResponseElement.getPrefix(); int len = attributes.getLength(); Attr attribute; for (int i = 0; i < len; i++) { attribute = (Attr) attributes.item(i); String attributeName = attribute.getName(); String attributeValue = attribute.getNodeValue(); String attributeNsUri = attribute.getNamespaceURI(); String attributePrefix = getPrefix(context.projectName, attributeNsUri); XmlSchemaAttribute xmlSchemaAttribute = getXmlSchemaAttributeByName(context.projectName, attributeName); boolean isGlobal = xmlSchemaAttribute != null; if (isGlobal) { attributeNsUri = xmlSchemaAttribute.getQName().getNamespaceURI(); attributePrefix = getPrefix(context.projectName, attributeNsUri); }//from w w w. j a v a 2s . c o m if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) { if (attributePrefix == null) { soapElement.addAttribute(soapEnvelope.createName(attributeName, prefix, targetNamespace), attributeValue); } else { soapElement.addAttribute( soapEnvelope.createName(attributeName, attributePrefix, attributeNsUri), attributeValue); } } else { soapElement.addAttribute(soapEnvelope.createName(attributeName), attributeValue); } } }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind Annotation element// w ww.j a v a 2 s . c o m * * @param element the Annotation element * @return Annotation data object * @throws InkMLException */ protected Annotation getAnnotation(final Element element) throws InkMLException { final Annotation annotation = new Annotation(); final NamedNodeMap attributesMap = element.getAttributes(); final int length = attributesMap.getLength(); for (int index = 0; index < length; index++) { final Attr attribute = (Attr) attributesMap.item(index); final String attributeName = attribute.getName(); if ("type".equals(attributeName)) { annotation.setType(attribute.getValue()); } else if ("encoding".equals(attributeName)) { annotation.setEncoding(attribute.getValue()); } else { annotation.addToOtherAttributesMap(attributeName, attribute.getValue()); } } final Node valueNode = element.getFirstChild(); if (null != valueNode) { annotation.setAnnotationTextValue(valueNode.getNodeValue()); } return annotation; }
From source file:com.hp.hpl.inkml.InkMLDOMParser.java
/** * Method to bind AnnotationXML element/* w w w . j a v a 2 s. c om*/ * * @param element the AnnotationXML element * @return AnnotationXML data object * @throws InkMLException */ protected AnnotationXML getAnnotationXML(final Element element) throws InkMLException { final AnnotationXML aXml = new AnnotationXML(); final NamedNodeMap attributesMap = element.getAttributes(); final int length = attributesMap.getLength(); for (int index = 0; index < length; index++) { final Attr attribute = (Attr) attributesMap.item(index); final String attributeName = attribute.getName(); if ("type".equals(attributeName)) { aXml.setType(attribute.getValue()); } else if ("encoding".equals(attributeName)) { aXml.setEncoding(attribute.getValue()); } else { aXml.addToOtherAttributesMap(attributeName, attribute.getValue()); } } InkMLDOMParser.LOG.finest("annotationXML received: " + element.toString()); final NodeList list = element.getChildNodes(); final int nChildren = list.getLength(); if (nChildren > 0) { for (int i = 0; i < nChildren; i++) { final Node node = list.item(i); if (!(node instanceof Element)) { continue; } final Element childElement = (Element) node; // get the tagName to use as Key in the valueMap final String tagName = childElement.getLocalName(); // String key = this.parentXPath+"/"+tagName; final String value = childElement.getFirstChild().getNodeValue(); // propertyElementsMap.put(key, childElement); // propertyElementsMap.put(key, value); aXml.addToPropertyElementsMap(tagName, value); InkMLDOMParser.LOG .finer("The property with name = " + tagName + " is added to the propertyElementsMap."); } } return aXml; }
From source file:com.gargoylesoftware.htmlunit.html.HtmlElement.java
/** * Sets the specified attribute. This method may be overridden by subclasses * which are interested in specific attribute value changes, but such methods <b>must</b> * invoke <tt>super.setAttributeNode()</tt>, and <b>should</b> consider the value of the * <tt>cloning</tt> parameter when deciding whether or not to execute custom logic. * * @param attribute the attribute to set * @return {@inheritDoc}//w ww .j a va 2 s .co m */ @Override public Attr setAttributeNode(final Attr attribute) { final String qualifiedName = attribute.getName(); final String oldAttributeValue = getAttribute(qualifiedName); final HtmlPage htmlPage = (HtmlPage) getPage(); final boolean mappedElement = isDirectlyAttachedToPage() && HtmlPage.isMappedElement(htmlPage, qualifiedName); if (mappedElement) { // cast is save here because isMappedElement checks for HtmlPage htmlPage.removeMappedElement(this); } final Attr result = super.setAttributeNode(attribute); if (mappedElement) { htmlPage.addMappedElement(this); } final HtmlAttributeChangeEvent htmlEvent; if (oldAttributeValue == ATTRIBUTE_NOT_DEFINED) { htmlEvent = new HtmlAttributeChangeEvent(this, qualifiedName, attribute.getValue()); fireHtmlAttributeAdded(htmlEvent); htmlPage.fireHtmlAttributeAdded(htmlEvent); } else { htmlEvent = new HtmlAttributeChangeEvent(this, qualifiedName, oldAttributeValue); fireHtmlAttributeReplaced(htmlEvent); htmlPage.fireHtmlAttributeReplaced(htmlEvent); } return result; }
From source file:jef.tools.XMLUtils.java
/** * ?//ww w . j a v a 2 s . c o m * * @param e * * @param subElementAsAttr * trueElement?<br> * * * <pre> * <Foo size="103" name="Karen"> * <dob>2012-4-12</dobh> * <dod>2052-4-12</dodh> * </Foo> * </pre> * * subElementAsAttr=falsedob,dod?true? * @return */ public static Map<String, String> getAttributesMap(Element e, boolean subElementAsAttr) { Map<String, String> attribs = new HashMap<String, String>(); if (e == null) return attribs; NamedNodeMap nmp = e.getAttributes(); for (int i = 0; i < nmp.getLength(); i++) { Attr child = (Attr) nmp.item(i); attribs.put(StringEscapeUtils.unescapeHtml(child.getName()), StringEscapeUtils.unescapeHtml(child.getValue())); } if (subElementAsAttr) { NodeList nds = e.getChildNodes(); for (int i = 0; i < nds.getLength(); i++) { Node node = nds.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) continue; Element sub = (Element) node; String key = sub.getNodeName(); String value = nodeText(sub); if (attribs.containsKey(key)) { attribs.put(key, attribs.get(key) + "," + value); } else { attribs.put(key, value); } } } return attribs; }
From source file:loci.formats.in.LIFReader.java
private void populateOriginalMetadata(Element root, Deque<String> nameStack) { String name = root.getNodeName(); if (root.hasAttributes() && !name.equals("Element") && !name.equals("Attachment") && !name.equals("LMSDataContainerHeader")) { nameStack.push(name);/*from w w w. j a va 2 s . c o m*/ String suffix = root.getAttribute("Identifier"); String value = root.getAttribute("Variant"); if (suffix == null || suffix.trim().length() == 0) { suffix = root.getAttribute("Description"); } StringBuffer key = new StringBuffer(); final Iterator<String> nameStackIterator = nameStack.descendingIterator(); while (nameStackIterator.hasNext()) { final String k = nameStackIterator.next(); key.append(k); key.append("|"); } if (suffix != null && value != null && suffix.length() > 0 && value.length() > 0 && !suffix.equals("HighInteger") && !suffix.equals("LowInteger")) { addSeriesMetaList(key.toString() + suffix, value); } else { NamedNodeMap attributes = root.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr) attributes.item(i); if (!attr.getName().equals("HighInteger") && !attr.getName().equals("LowInteger")) { addSeriesMeta(key.toString() + attr.getName(), attr.getValue()); } } } } NodeList children = root.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Object child = children.item(i); if (child instanceof Element) { populateOriginalMetadata((Element) child, nameStack); } } if (root.hasAttributes() && !name.equals("Element") && !name.equals("Attachment") && !name.equals("LMSDataContainerHeader")) { nameStack.pop(); } }
From source file:com.gargoylesoftware.htmlunit.html.HtmlPage.java
/** * <p>Returns all namespaces defined in the root element of this page.</p> * <p>The default namespace has a key of an empty string.</p> * @return all namespaces defined in the root element of this page */// www.jav a2s . co m public Map<String, String> getNamespaces() { final org.w3c.dom.NamedNodeMap attributes = getDocumentElement().getAttributes(); final Map<String, String> namespaces = new HashMap<>(); for (int i = 0; i < attributes.getLength(); i++) { final Attr attr = (Attr) attributes.item(i); String name = attr.getName(); if (name.startsWith("xmlns")) { int startPos = 5; if ((name.length() > 5) && (name.charAt(5) == ':')) { startPos = 6; } name = name.substring(startPos); namespaces.put(name, attr.getValue()); } } return namespaces; }
From source file:lucee.runtime.img.Image.java
private void addMetaddata(Struct parent, String name, Node node) { // attributes NamedNodeMap attrs = node.getAttributes(); Attr attr; int len = attrs.getLength(); if (len == 1 && "value".equals(attrs.item(0).getNodeName())) { parent.setEL(name, attrs.item(0).getNodeValue()); } else {//from w ww . j av a2s . c o m Struct sct = metaGetChild(parent, name); for (int i = attrs.getLength() - 1; i >= 0; i--) { attr = (Attr) attrs.item(i); sct.setEL(attr.getName(), attr.getValue()); } } // child nodes NodeList children = XMLUtil.getChildNodes(node, Node.ELEMENT_NODE); Element el; for (int i = children.getLength() - 1; i >= 0; i--) { el = (Element) children.item(i); Struct sct = metaGetChild(parent, name); addMetaddata(sct, el.getNodeName(), children.item(i)); } }