attr.setPrefix(attrPrefix); attr.setValue(attrValue); element.setAttributeNodeNS(attr);
public void onAttr( Attr a ) { String uri = nullAdjust(a.getNamespaceURI()); if("".equals(uri)) return; // do nothing. if(uri.equals(XMLNS_URI)) return; // don't touch xmlns declarations. String prefix = (String)uri2prefix.get(uri); a.setPrefix(prefix); } });
protected void runTest() throws Throwable { Document document = dbf.newDocumentBuilder().newDocument(); Attr attr = document.createAttributeNS("urn:test", "p:test"); attr.setPrefix(null); assertNull(attr.getPrefix()); } }
public static void setQNameAttribute(Element element, QName attributeName, QName attributeValue) { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttributeNS(attributeName.getNamespaceURI(), attributeName.getLocalPart()); String namePrefix = lookupOrCreateNamespaceDeclaration(element, attributeName.getNamespaceURI(), attributeName.getPrefix(), element, true); attr.setPrefix(namePrefix); setQNameAttribute(element, attr, attributeValue, element); }
protected void runTest() throws Throwable { Document document = dbf.newDocumentBuilder().newDocument(); Attr attr = document.createAttributeNS("urn:ns", "p:test"); attr.setPrefix("q"); assertEquals("q", attr.getPrefix()); assertEquals("q:test", attr.getName()); } }
public static void setQNameAttribute(Element element, QName attributeName, QName attributeValue, Element definitionElement) { Document doc = element.getOwnerDocument(); Attr attr = doc.createAttributeNS(attributeName.getNamespaceURI(), attributeName.getLocalPart()); String namePrefix = lookupOrCreateNamespaceDeclaration(element, attributeName.getNamespaceURI(), attributeName.getPrefix(), element, true); attr.setPrefix(namePrefix); setQNameAttribute(element, attr, attributeValue, definitionElement); }
protected void runTest() throws Throwable { Document document = dbf.newDocumentBuilder().newDocument(); Attr attr = document.createAttributeNS(null, "test"); try { attr.setPrefix("p"); fail("Expected DOMException"); } catch (DOMException ex) { assertEquals(DOMException.NAMESPACE_ERR, ex.code); } } }
private Attr bufferAttribute( Element element, Attribute attribute ) { QName name = attribute.getName(); String prefix = name.getPrefix(); String uri = name.getNamespaceURI(); Attr node; if( uri == null || uri.isEmpty() ) { node = document.createAttribute( name.getLocalPart() ); element.setAttributeNode( node ); } else { node = document.createAttributeNS( uri, name.getLocalPart() ); if( prefix != null && !prefix.isEmpty() ) { node.setPrefix( prefix ); } element.setAttributeNodeNS( node ); } node.setTextContent( attribute.getValue() ); return node; }
private Attr bufferAttribute( Element element, Attribute attribute ) { QName name = attribute.getName(); String prefix = name.getPrefix(); String uri = name.getNamespaceURI(); Attr node; if( uri == null || uri.isEmpty() ) { node = document.createAttribute( name.getLocalPart() ); element.setAttributeNode( node ); } else { node = document.createAttributeNS( uri, name.getLocalPart() ); if( prefix != null && !prefix.isEmpty() ) { node.setPrefix( prefix ); } element.setAttributeNodeNS( node ); } node.setTextContent( attribute.getValue() ); return node; }
/** * Add an attribute to the specified element * @param parent the element to which we add the attribute * @param ns the namespace of the attribute * @param attributeName the name of the attribute * @param value the value of the attribute * @return the attribute */ public static final Attr addAttribute(Element parent, String ns, String attributeName, String value) { Document doc = parent.getOwnerDocument(); Attr ret = doc.createAttributeNS(ns, attributeName); ret.setTextContent(value); ret.setPrefix(OJBC_NAMESPACE_CONTEXT.getPrefix(ns)); parent.setAttributeNode(ret); return ret; }
String prefix = qname.getPrefix(); if (prefix != null && prefix.length() > 0) { attr.setPrefix(prefix);
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Element element; NodeList elementList; Attr attribute; doc = (Document) load("staffNS", true); elementList = doc.getElementsByTagName("employee"); element = (Element) elementList.item(0); attribute = element.getAttributeNode("xmlns"); { boolean success = false; try { attribute.setPrefix("xml"); } catch (DOMException ex) { success = (ex.code == DOMException.NAMESPACE_ERR); } assertTrue("throw_NAMESPACE_ERR", success); } } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Element addrNode; Attr addrAttr; doc = (Document) load("staffNS", true); elementList = doc.getElementsByTagName("address"); addrNode = (Element) elementList.item(3); addrAttr = addrNode.getAttributeNode("xmlns"); { boolean success = false; try { addrAttr.setPrefix("xxx"); } catch (DOMException ex) { success = (ex.code == DOMException.NAMESPACE_ERR); } assertTrue("throw_NAMESPACE_ERR", success); } } /**
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Attr attribute; doc = (Document) load("staffNS", true); attribute = doc.createAttributeNS("http://www.w3.org/DOM/Test/L2", "abc:elem"); { boolean success = false; try { attribute.setPrefix("xmlns"); } catch (DOMException ex) { success = (ex.code == DOMException.NAMESPACE_ERR); } assertTrue("throw_NAMESPACE_ERR", success); } } /**
protected Node cloneNode(Document doc, boolean deep) { Attr attr = doc.createAttributeNS(getNamespaceURI(), getLocalName()); attr.setValue(getValue()); attr.setPrefix(getPrefix()); return attr; }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Element addrNode; Attr addrAttr; doc = (Document) load("staffNS", true); elementList = doc.getElementsByTagName("emp:address"); addrNode = (Element) elementList.item(0); assertNotNull("empAddrNotNull", addrNode); addrAttr = addrNode.getAttributeNode("emp:domestic"); { boolean success = false; try { addrAttr.setPrefix("xmlns"); } catch (DOMException ex) { success = (ex.code == DOMException.NAMESPACE_ERR); } assertTrue("throw_NAMESPACE_ERR", success); } } /**
public void insertText(XmlMarshallingContext ctx, String fieldText) { Element parent = (Element) ctx.getParent(); // format the field text (a null field value may not return null if a custom type handler was configured) String text = fieldText; // nothing to marshal if minOccurs is 0 if (text == null && isLazy()) { return; } if (parent.getNodeType() == Node.ELEMENT_NODE) { if (text == null) { text = ""; } Attr att = parent.getOwnerDocument().createAttributeNS(getNamespace(), getLocalName()); att.setValue(text); att.setPrefix(getPrefix()); ((Element)parent).setAttributeNode(att); } }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Element element; Attr attribute; NodeList elementList; String nullNS = null; doc = (Document) load("staffNS", true); elementList = doc.getElementsByTagName("emp:employee"); element = (Element) elementList.item(0); assertNotNull("empEmployeeNotNull", element); attribute = element.getAttributeNodeNS(nullNS, "defaultAttr"); { boolean success = false; try { attribute.setPrefix("test"); } catch (DOMException ex) { success = (ex.code == DOMException.NAMESPACE_ERR); } assertTrue("nodesetprefix04", success); } } /**
Document doc = (WsstarCommonUtils.getNamespaceDocumentBuilder()).newDocument(); Attr topicAttr = doc.createAttributeNS(WstopConstants.WS_TOPICS_NAMESPACE_URI, "topic"); topicAttr.setPrefix(WstopConstants.WS_TOPICS_PREFIX); topicAttr.setTextContent("true");
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Element element; Attr attribute; Attr newAttribute; Node setNode; NodeList elementList; String attrName; String newAttrName; doc = (Document) load("staffNS", true); elementList = doc.getElementsByTagName("address"); element = (Element) elementList.item(1); newAttribute = doc.createAttributeNS("http://www.w3.org/DOM/Test", "test:address"); setNode = element.setAttributeNodeNS(newAttribute); newAttribute.setPrefix("dom"); attribute = element.getAttributeNodeNS("http://www.usa.com", "domestic"); attrName = attribute.getNodeName(); newAttrName = newAttribute.getNodeName(); assertEquals("nodesetprefix02_attrName", "dmstc:domestic", attrName); assertEquals("nodesetprefix02_newAttrName", "dom:address", newAttrName); } /**