public static String getXsiType(org.w3c.dom.Element element) { Attr a = element.getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "type"); return (a == null ? null : a.getTextContent()); }
private String getOptionalAttribute(Element element, String name) { Attr att = element.getAttributeNode(name); if (att == null) { return null; } else { return doPropertySubstitution(att.getTextContent()); } }
public static String getXsiType(org.w3c.dom.Element element) { Attr a = element.getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "type"); return (a == null ? null : a.getTextContent()); }
public static QName getQNameValue(Attr attr) { return resolveQName(attr, attr.getTextContent()); }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String channelRef = element.getAttribute("channel"); Assert.hasText(channelRef, "channel attribute must be provided"); builder.addConstructorArgReference(channelRef); Element eplElements = DomUtils.getChildElementByTagName(element, "epl"); if (eplElements != null) { builder.addConstructorArgValue(eplElements.getTextContent()); } else { builder.addConstructorArgValue(null); } Attr templateNameNode = element.getAttributeNode("template-name"); if (templateNameNode != null) { builder.addPropertyValue("templateName", templateNameNode.getTextContent()); } }
private static void sendAttributeToWriter(XmlWriter xwriter, Attr attr) { if (attr.isId()) { xwriter.writeIdAttribute(attr.getPrefix(), attr.getNamespaceURI(), attr.getLocalName(), attr.getTextContent()); } else { if (attr.getNamespaceURI() == null && attr.getLocalName() == null) { // Level 1 DOM attribute xwriter.writeAttribute(null, null, attr.getName(), attr.getTextContent()); } else { xwriter.writeAttribute(attr.getPrefix(), attr.getNamespaceURI(), attr.getLocalName(), attr.getTextContent()); } } }
private static boolean compareAttributesIsSubset(NamedNodeMap subset, NamedNodeMap superset, boolean considerNamespacePrefixes) { for (int i = 0; i < subset.getLength(); i++) { Node aItem = subset.item(i); Attr aAttr = (Attr) aItem; if (!considerNamespacePrefixes && isNamespaceDefinition(aAttr)) { continue; } if (StringUtils.isBlank(aAttr.getLocalName())) { // this is strange, but it can obviously happen continue; } QName aQname = new QName(aAttr.getNamespaceURI(),aAttr.getLocalName()); Attr bAttr = findAttributeByQName(superset,aQname); if (bAttr == null) { return false; } if (!StringUtils.equals(aAttr.getTextContent(),bAttr.getTextContent())) { return false; } } return true; }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elemList; Element elem; Attr attr; String textContent; doc = (Document) load("hc_staff", false); elemList = doc.getElementsByTagName("p"); elem = (Element) elemList.item(3); attr = elem.getAttributeNode("dir"); textContent = attr.getTextContent(); assertEquals("nodegettextcontent06", "rtl", textContent); } /**
private static void append(StringBuffer buffer, Node node) { if (node instanceof Text) { Text text = (Text) node; buffer.append(text.getTextContent()); } else if (node instanceof Attr) { Attr attribute = (Attr) node; buffer.append(attribute.getTextContent()); } else if (node instanceof Element) { Element element = (Element) node; append(buffer, element.getChildNodes()); } else if (node instanceof Document) { Document doc = (Document) node; append(buffer, doc.getChildNodes()); } }
/** * Initialize object's namespace context (recursively). * * @param el * object's associated element. */ private void initNSContext(Element el) { if (el.getParentNode() != null && el.getParentNode().getNodeType() == Node.ELEMENT_NODE) initNSContext((Element) el.getParentNode()); NamedNodeMap attrs = el.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Attr attr = (Attr) attrs.item(i); if (!attr.getName().startsWith("xmlns:")) continue; String prefix = attr.getLocalName(); String uri = attr.getValue(); _nsContext.register(prefix, uri); } Attr dflt = el.getAttributeNode("xmlns"); if (dflt != null) { _nsContext.register("", dflt.getTextContent()); } }
@Override public String toString() { return "ValueParser(DOMa, " + PrettyPrinter.prettyPrint(DOMUtil.getQName(attr)) + ": " + attr.getTextContent() + ")"; }
static boolean canBeMerged( Node node1, Node node2, String requiredTagName ) { if ( node1.getNodeType() != Node.ELEMENT_NODE || node2.getNodeType() != Node.ELEMENT_NODE ) return false; Element element1 = (Element) node1; Element element2 = (Element) node2; if ( !equals( requiredTagName, element1.getTagName() ) || !equals( requiredTagName, element2.getTagName() ) ) return false; NamedNodeMap attributes1 = element1.getAttributes(); NamedNodeMap attributes2 = element2.getAttributes(); if ( attributes1.getLength() != attributes2.getLength() ) return false; for ( int i = 0; i < attributes1.getLength(); i++ ) { final Attr attr1 = (Attr) attributes1.item( i ); final Attr attr2; if ( isNotEmpty( attr1.getNamespaceURI() ) ) attr2 = (Attr) attributes2.getNamedItemNS( attr1.getNamespaceURI(), attr1.getLocalName() ); else attr2 = (Attr) attributes2.getNamedItem( attr1.getName() ); if ( attr2 == null || !equals( attr1.getTextContent(), attr2.getTextContent() ) ) return false; } return true; }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elemList; Element elem; Attr attr; String textContent; doc = (Document) load("hc_staff", true); elemList = doc.getElementsByTagName("p"); elem = (Element) elemList.item(3); elem.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang", "en-US"); attr = elem.getAttributeNodeNS("http://www.w3.org/XML/1998/namespace", "lang"); textContent = attr.getTextContent(); assertEquals("nodegettextcontent07", "en-US", textContent); } /**
private static <T> T parsePrimitiveAttrValue(Attr attr, QName typeName, XNodeProcessorEvaluationMode mode) throws SchemaException { if (DOMUtil.XSD_QNAME.equals(typeName)) { try { return (T) DOMUtil.getQNameValue(attr); } catch (IllegalArgumentException e) { return processIllegalArgumentException(attr.getTextContent(), typeName, e, mode); // primitive way of ensuring compatibility mode } } if (XmlTypeConverter.canConvert(typeName)) { String stringValue = attr.getTextContent(); try { return XmlTypeConverter.toJavaValue(stringValue, typeName); } catch (IllegalArgumentException e) { return processIllegalArgumentException(attr.getTextContent(), typeName, e, mode); // primitive way of ensuring compatibility mode } } else { throw new SchemaException("Cannot convert attribute '"+attr+"' to "+typeName); } }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elemList; Element elem; Attr attr; String textContent; doc = (Document) load("hc_staff", true); elemList = doc.getElementsByTagName("p"); elem = (Element) elemList.item(3); attr = elem.getAttributeNode("dir"); attr.setTextContent("NA"); textContent = attr.getTextContent(); assertEquals("nodesettextcontent05", "NA", textContent); } /**
/** * Gets the XSI type for a given element if it has one. * * @param e the element * * @return the type or null */ public static QName getXSIType(Element e) { if (hasXSIType(e)) { Attr attribute = e.getAttributeNodeNS(XMLConstants.XSI_NS, "type"); String attributeValue = attribute.getTextContent().trim(); StringTokenizer tokenizer = new StringTokenizer(attributeValue, ":"); String prefix = null; String localPart; if (tokenizer.countTokens() > 1) { prefix = tokenizer.nextToken(); localPart = tokenizer.nextToken(); } else { localPart = tokenizer.nextToken(); } return constructQName(e.lookupNamespaceURI(prefix), localPart, prefix); } return null; }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elemList; Element elem; Attr attr; Attr attrNode; String textContent; doc = (Document) load("hc_staff", true); elem = doc.createElementNS("http://www.w3.org/1999/xhtml", "p"); attr = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang"); attrNode = elem.setAttributeNodeNS(attr); attr.setTextContent("NA"); textContent = attr.getTextContent(); assertEquals("nodesettextcontent06", "NA", textContent); } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elemList; Element elem; Attr att; Attr attr; Attr replacedAttr; String textContent; doc = (Document) load("barfoo", false); elem = doc.createElementNS("http://www.w3.org/1999/xhtml", "p"); att = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang"); replacedAttr = elem.setAttributeNodeNS(att); attr = elem.getAttributeNodeNS("http://www.w3.org/XML/1998/namespace", "lang"); textContent = attr.getTextContent(); assertEquals("nodegettextcontent08", "", textContent); } /**
/** * Constructs a QName from an attributes value. * * @param attribute the attribute with a QName value * * @return a QName from an attributes value, or null if the given attribute is null */ public static QName getAttributeValueAsQName(Attr attribute) { if (attribute == null || DatatypeHelper.isEmpty(attribute.getValue())) { return null; } String attributeValue = attribute.getTextContent(); String[] valueComponents = attributeValue.split(":"); if (valueComponents.length == 1) { return constructQName(attribute.lookupNamespaceURI(null), valueComponents[0], null); } else { return constructQName(attribute.lookupNamespaceURI(valueComponents[0]), valueComponents[1], valueComponents[0]); } }
/** * Constructs a QName from an attributes value. * * @param attribute the attribute with a QName value * * @return a QName from an attributes value, or null if the given attribute is null */ public static QName getAttributeValueAsQName(Attr attribute) { if (attribute == null || DatatypeHelper.isEmpty(attribute.getValue())) { return null; } String attributeValue = attribute.getTextContent(); String[] valueComponents = attributeValue.split(":"); if (valueComponents.length == 1) { return constructQName(attribute.lookupNamespaceURI(null), valueComponents[0], null); } else { return constructQName(attribute.lookupNamespaceURI(valueComponents[0]), valueComponents[1], valueComponents[0]); } }