public void serializeAttributes(Object element, XMLSerializer target) throws SAXException { NamedNodeMap al = ((Element)element).getAttributes(); int len = al.getLength(); for( int i=0; i<len; i++ ) { Attr a = (Attr)al.item(i); // work defensively String uri = a.getNamespaceURI(); if(uri==null) uri=""; String local = a.getLocalName(); String name = a.getName(); if(local==null) local = name; if (uri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE) && ("nil".equals(local))) { isNilIncluded = true; } if(name.startsWith("xmlns")) continue;// DOM reports ns decls as attributes target.attribute(uri,local,a.getValue()); } }
/** * Loads the given attribute in the current sequence. * * @param attr The W3C DOM attribute node to load. */ private void load(Attr attr) { handlePrefixMapping(attr.getNamespaceURI(), attr.getPrefix()); load(this.efactory.makeAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getNodeName(), attr.getValue())); }
String namespaceURI0 = attr0.getNamespaceURI(); String namespaceURI1 = attr1.getNamespaceURI(); if (isNamespaceAttr1) { String localname0 = attr0.getLocalName(); String localname1 = attr1.getLocalName(); return attr0.getLocalName().compareTo(attr1.getLocalName());
int length = atts.getLength(); Attr att = (Attr) atts.item(i); String attributeNamespace = att.getNamespaceURI(); if ("http://www.w3.org/2000/xmlns/".equals(attributeNamespace)) { Attr att = (Attr) atts.item(i); String attributeNamespace = att.getNamespaceURI(); if ("http://www.w3.org/2000/xmlns/".equals(attributeNamespace)) { NamespaceNode ns =
private static void fixupAttrsSingle(Element e) throws DOMException { removeXmlBase(e); Map<String, String> replace = new HashMap<String, String>(); NamedNodeMap attrs = e.getAttributes(); for (int j = 0; j < attrs.getLength(); j++) { Attr attr = (Attr) attrs.item(j); if (attr.getNamespaceURI() == null && !attr.getName().equals("xmlns")) { // NOI18N replace.put(attr.getName(), attr.getValue()); } } for (Map.Entry<String, String> entry : replace.entrySet()) { e.removeAttribute(entry.getKey()); e.setAttributeNS(null, entry.getKey(), entry.getValue()); } } private static void removeXmlBase(Element e) {
protected Attribute createAttribute(org.w3c.dom.Attr newAttr) { QName qname = null; String name = newAttr.getLocalName(); if (name != null) { String prefix = newAttr.getPrefix(); String uri = newAttr.getNamespaceURI(); qname = getDocumentFactory().createQName(name, prefix, uri); } else { name = newAttr.getName(); qname = getDocumentFactory().createQName(name); } return new DOMAttribute(qname, newAttr.getValue()); }
public Attr setAttributeNodeNS(Attr newAttr) throws DOMException { AttrImpl newAttrImpl = (AttrImpl) newAttr; if (newAttrImpl.document != this.document) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null); } if (newAttrImpl.getOwnerElement() != null) { throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, null); } AttrImpl oldAttrImpl = null; int i = indexOfAttributeNS(newAttr.getNamespaceURI(), newAttr.getLocalName()); if (i != -1) { oldAttrImpl = attributes.get(i); attributes.remove(i); } attributes.add(newAttrImpl); newAttrImpl.ownerElement = this; return oldAttrImpl; }
public void run() { Set<String> declaredPrefixes = new HashSet<String>(); for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) { NamedNodeMap atts = n.getAttributes(); if(atts==null) continue; // broken DOM. but be graceful. for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); String nsUri = a.getNamespaceURI(); if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) continue; // not a namespace declaration String prefix = a.getLocalName(); if(prefix==null) continue; // broken DOM. skip to be safe if(prefix.equals("xmlns")) { prefix = ""; } String value = a.getValue(); if(value==null) continue; // broken DOM. skip to be safe if(declaredPrefixes.add(prefix)) { serializer.addInscopeBinding(value,prefix); } } } } }
public org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr newAttr) throws DOMException { Attribute attribute = attribute(newAttr.getNamespaceURI(), newAttr .getLocalName()); if (attribute != null) { attribute.setValue(newAttr.getValue()); } else { attribute = createAttribute(newAttr); add(attribute); } return DOMNodeHelper.asDOMAttr(attribute); }
protected Attribute attribute(org.w3c.dom.Attr attr) { return attribute(DOCUMENT_FACTORY.createQName(attr.getLocalName(), attr .getPrefix(), attr.getNamespaceURI())); }
protected Map defineNamespaces(Element element, Map namespaces) { Map answer = null; String prefix = element.getPrefix(); if (prefix != null && prefix.length() > 0 && !namespaces.containsKey(prefix)) { answer = new HashMap(namespaces); defineNamespace(answer, prefix, element.getNamespaceURI()); } NamedNodeMap attributes = element.getAttributes(); int length = attributes.getLength(); for (int i = 0; i < length; i++) { Attr attribute = (Attr) attributes.item(i); prefix = attribute.getPrefix(); if (prefix != null && prefix.length() > 0 && !namespaces.containsKey(prefix)) { if (answer == null) { answer = new HashMap(namespaces); } defineNamespace(answer, prefix, attribute.getNamespaceURI()); } } return (answer != null) ? answer : namespaces; }
private void parseDescriptionRootAttr(XMPMetadata xmp, Element description, Attr attr, TypeMapping tm) throws XmpSchemaException, XmpParsingException String namespace = attr.getNamespaceURI(); XMPSchema schema = xmp.getSchema(namespace); if (schema == null && tm.getSchemaFactory(namespace) != null) new QName(attr.getNamespaceURI(), attr.getLocalName())); attr.getLocalName(), attr.getValue(), type.type()); container.addProperty(sp); e.getMessage() + " in " + schema.getPrefix() + ":" + attr.getLocalName(), e);
static class LoggingErrorListener implements ErrorListener { // See http://www.cafeconleche.org/slides/sd2003west/xmlandjava/346.html boolean strict; public LoggingErrorListener(boolean strict) { } public void warning(TransformerException exception) { log.warn(exception.getMessage(), exception); // Don't throw an exception and stop the processor // just for a warning; but do log the problem } public void error(TransformerException exception) throws TransformerException { log.error(exception.getMessage(), exception); // XSLT is not as draconian as XML. There are numerous errors // which the processor may but does not have to recover from; // e.g. multiple templates that match a node with the same // priority. If I do not want to allow that, I'd throw this // exception here. if (strict) { throw exception; }
/** * {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { if (attribute.getLocalName().equals(LangBearing.XML_LANG_ATTR_LOCAL_NAME) && SAMLConstants.XML_NS.equals(attribute.getNamespaceURI())) { Keywords keywords = (Keywords) samlObject; keywords.setXMLLang(attribute.getValue()); } }
public void serializeURIs(Object element, XMLSerializer target) { NamedNodeMap al = ((Element)element).getAttributes(); int len = al.getLength(); NamespaceContext2 context = target.getNamespaceContext(); for( int i=0; i<len; i++ ) { Attr a = (Attr)al.item(i); if ("xmlns".equals(a.getPrefix())) { context.force(a.getValue(), a.getLocalName()); continue; } if ("xmlns".equals(a.getName())) { if (element instanceof org.w3c.dom.Element) { context.declareNamespace(a.getValue(), null, false); continue; } else { context.force(a.getValue(), ""); continue; } } String nsUri = a.getNamespaceURI(); if(nsUri!=null && nsUri.length()>0) context.declareNamespace( nsUri, a.getPrefix(), true ); } }
/** * {@inheritDoc} */ @Override protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { if (attribute.getLocalName().equals(LangBearing.XML_LANG_ATTR_LOCAL_NAME) && XMLConstants.XML_NS.equals(attribute.getNamespaceURI())) { Keywords keywords = (Keywords) samlObject; keywords.setXMLLang(attribute.getValue()); } }
return; NamedNodeMap attrs = e.getAttributes(); int attrsLength = attrs.getLength(); for (int i = 0; i < attrsLength; i++) { Attr attribute = (Attr) attrs.item(i); String NName = attribute.getLocalName(); String NValue = attribute.getNodeValue(); if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI()) && (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue))) { ns.addMapping(NName, NValue, attribute);
public String getAttributeNS(String namespaceURI, String localName) { for (int i=0; i<attrs.length; i++) { if (attrs[i].getLocalName().equals(localName) && nsEquals(attrs[i].getNamespaceURI(), namespaceURI)) { return attrs[i].getValue(); } } return ""; }
NamedNodeMap attrs = e.getAttributes(); int attrsLength = attrs.getLength(); for (int i = 0; i < attrsLength; i++) { Attr attribute = (Attr) attrs.item(i); String NName = attribute.getLocalName(); String NValue = attribute.getNodeValue(); if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI())) { if (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) { ns.addMapping(NName, NValue, attribute); } else if (!"id".equals(NName) && XML_LANG_URI.equals(attribute.getNamespaceURI())) { xmlattrStack.addXmlnsAttr(attribute);
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { Logo logo = (Logo) samlObject; if (attribute.getLocalName().equals(LangBearing.XML_LANG_ATTR_LOCAL_NAME) && XMLConstants.XML_NS.equals(attribute.getNamespaceURI())) { logo.setXMLLang(attribute.getValue()); } else if (attribute.getLocalName().equals(Logo.HEIGHT_ATTR_NAME)) { logo.setHeight(Integer.valueOf(attribute.getValue())); } else if (attribute.getLocalName().equals(Logo.WIDTH_ATTR_NAME)) { logo.setWidth(Integer.valueOf(attribute.getValue())); } }