当前位置: 首页>>代码示例>>Java>>正文


Java Attr.setValue方法代码示例

本文整理汇总了Java中org.w3c.dom.Attr.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java Attr.setValue方法的具体用法?Java Attr.setValue怎么用?Java Attr.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.Attr的用法示例。


在下文中一共展示了Attr.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: declareExtensionNamespace

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Adds the specified namespace URI to the jaxb:extensionBindingPrefixes
 * attribute of the target document.
 */
private void declareExtensionNamespace( Element target, String nsUri ) {
    // look for the attribute
    Element root = target.getOwnerDocument().getDocumentElement();
    Attr att = root.getAttributeNodeNS(Const.JAXB_NSURI,EXTENSION_PREFIXES);
    if( att==null ) {
        String jaxbPrefix = allocatePrefix(root,Const.JAXB_NSURI);
        // no such attribute. Create one.
        att = target.getOwnerDocument().createAttributeNS(
            Const.JAXB_NSURI,jaxbPrefix+':'+EXTENSION_PREFIXES);
        root.setAttributeNodeNS(att);
    }

    String prefix = allocatePrefix(root,nsUri);
    if( att.getValue().indexOf(prefix)==-1 )
        // avoid redeclaring the same namespace twice.
        att.setValue( att.getValue()+' '+prefix);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:Internalizer.java

示例2: startElement

import org.w3c.dom.Attr; //导入方法依赖的package包/类
@Override
public void startElement(
    final String uri, final String localName, final String qName, final Attributes attributes
) {

    final Element currentElement;
    if (localName != null && !localName.isEmpty()) {
        currentElement = this.myDoc.createElementNS(uri, localName);
    } else {
        currentElement = this.myDoc.createElement(qName);
    }

    this.markLocation(currentElement, START_LOC);
    this.appendElement(currentElement);

    if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {
            final Attr nextAttr = this.createAndAppendAttribute(currentElement, attributes, i);
            nextAttr.setValue(attributes.getValue(i));
            this.markLocation(nextAttr, START_LOC);
        }
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:24,代码来源:ValidateContextImpl.java

示例3: duplicateNode

import org.w3c.dom.Attr; //导入方法依赖的package包/类
static Node duplicateNode(Document document, Node node) {
    Node newNode;
    if (node.getNamespaceURI() != null) {
        newNode = document.createElementNS(node.getNamespaceURI(), node.getLocalName());
    } else {
        newNode = document.createElement(node.getNodeName());
    }

    // copy the attributes
    NamedNodeMap attributes = node.getAttributes();
    for (int i = 0 ; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);

        Attr newAttr;
        if (attr.getNamespaceURI() != null) {
            newAttr = document.createAttributeNS(attr.getNamespaceURI(), attr.getLocalName());
            newNode.getAttributes().setNamedItemNS(newAttr);
        } else {
            newAttr = document.createAttribute(attr.getName());
            newNode.getAttributes().setNamedItem(newAttr);
        }

        newAttr.setValue(attr.getValue());
    }

    // then duplicate the sub-nodes.
    NodeList children = node.getChildNodes();
    for (int i = 0 ; i < children.getLength() ; i++) {
        Node child = children.item(i);
        if (child.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        Node duplicatedChild = duplicateNode(document, child);
        newNode.appendChild(duplicatedChild);
    }

    return newNode;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:39,代码来源:NodeUtils.java

示例4: assignAttributeValue

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Sets the text value of an attribute on a provided element if set in the attributeValueMap table.
 * 
 * @param attName the attribute local name.
 * @param contentElem the element to set the attribute on.
 */
public void assignAttributeValue(String attName,
                                 Element contentElem) {
   if (null != attName && null != contentElem) {
      String attValue = null;
      if (sampleXML) {
         attValue = "?";
      }
      else {
         attValue = getAttributeValue(attName, contentElem);
      }
      if (null != attValue) {
         Attr att = DocumentHelper.createAttribute(generatedDoc, "", attName);
         att.setValue(attValue);
         contentElem.setAttributeNode(att);
      }
   }
}
 
开发者ID:mqsysadmin,项目名称:dpdirect,代码行数:24,代码来源:SchemaLoader.java

示例5: marshallAttributes

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
protected void marshallAttributes(XMLObject samlObject, Element domElement) throws MarshallingException {
    Logo logo = (Logo) samlObject;

    if (logo.getXMLLang() != null) {
        Attr attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), SAMLConstants.XML_NS,
                LangBearing.XML_LANG_ATTR_LOCAL_NAME, SAMLConstants.XML_PREFIX);
        attribute.setValue(logo.getXMLLang());
        domElement.setAttributeNodeNS(attribute);
    }
    if (logo.getHeight() != null) {
        domElement.setAttributeNS(null, Logo.HEIGHT_ATTR_NAME, logo.getHeight().toString());
    }
    if (logo.getWidth() != null) {
        domElement.setAttributeNS(null, Logo.WIDTH_ATTR_NAME, logo.getWidth().toString());
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:LogoMarshaller.java

示例6: setNodeTextValue

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * This method assigns a new value to a node.
 * 
 * @param aNode is the node for which the new value is assigned
 * @param asNewValue is the new value
 */
public static void setNodeTextValue(Node aNode,
                                    String asNewValue) {
   if (aNode instanceof Element) {
      if (aNode.getFirstChild() == null || aNode.getFirstChild().getNodeType() != org.w3c.dom.Node.TEXT_NODE)
         aNode.appendChild(aNode.getOwnerDocument().createTextNode(asNewValue));
      else
         aNode.getFirstChild().setNodeValue(asNewValue);
   }
   else if (aNode instanceof Attr) {
      Attr attribute = (Attr) aNode;
      attribute.setValue(asNewValue);
   }
}
 
开发者ID:mqsysadmin,项目名称:dpdirect,代码行数:20,代码来源:DocumentHelper.java

示例7: writeAttribute

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
 * @param localName {@inheritDoc}
 * @param value {@inheritDoc}
 * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 */
public void writeAttribute(String localName, String value) throws XMLStreamException {

    if(currentNode.getNodeType() == Node.ELEMENT_NODE){
        Attr attr = ownerDoc.createAttribute(localName);
        attr.setValue(value);
        ((Element)currentNode).setAttributeNode(attr);
    }else{
        //Convert node type to String
        throw new IllegalStateException("Current DOM Node type  is "+ currentNode.getNodeType() +
                "and does not allow attributes to be set ");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:XMLDOMWriterImpl.java

示例8: marshallAttributes

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
    AuthnContextDecl authnCtxDecl = (AuthnContextDecl) xmlObject;

    Attr attribute;
    for (Entry<QName, String> entry : authnCtxDecl.getUnknownAttributes().entrySet()) {
        attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
        attribute.setValue(entry.getValue());
        domElement.setAttributeNodeNS(attribute);
        if (Configuration.isIDAttribute(entry.getKey())
                || authnCtxDecl.getUnknownAttributes().isIDAttribute(entry.getKey())) {
            attribute.getOwnerElement().setIdAttributeNode(attribute, true);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:AuthnContextDeclMarshaller.java

示例9: normalizeAttributeValue

import org.w3c.dom.Attr; //导入方法依赖的package包/类
final String normalizeAttributeValue(String value, Attr attr) {
    if (!attr.getSpecified()){
        // specified attributes should already have a normalized form
        // since those were added by validator
        return value;
    }
    int end = value.length();
    // ensure capacity
    if (fNormalizedValue.ch.length < end) {
        fNormalizedValue.ch = new char[end];
    }
    fNormalizedValue.length = 0;
    boolean normalized = false;
    for (int i = 0; i < end; i++) {
        char c = value.charAt(i);
        if (c==0x0009 || c==0x000A) {
           fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
           normalized = true;
        }
        else if(c==0x000D){
           normalized = true;
           fNormalizedValue.ch[fNormalizedValue.length++] = ' ';
           int next = i+1;
           if (next < end && value.charAt(next)==0x000A) i=next; // skip following xA
        }
        else {
            fNormalizedValue.ch[fNormalizedValue.length++] = c;
        }
    }
    if (normalized){
       value = fNormalizedValue.toString();
       attr.setValue(value);
    }
    return value;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:DOMNormalizer.java

示例10: testSetAttributeNode

import org.w3c.dom.Attr; //导入方法依赖的package包/类
@Test
public void testSetAttributeNode() throws Exception {
    final String attrName = "myAttr";
    final String attrValue = "attrValue";
    Document document = createDOM("ElementSample02.xml");
    Element elemNode = document.createElement("pricetag2");
    Attr myAttr = document.createAttribute(attrName);
    myAttr.setValue(attrValue);

    assertNull(elemNode.setAttributeNode(myAttr));
    assertEquals(elemNode.getAttribute(attrName), attrValue);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:ElementTest.java

示例11: marshallAttributes

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected void marshallAttributes(XMLObject samlElement, Element domElement) {
    EntityDescriptor entityDescriptor = (EntityDescriptor) samlElement;

    // Set the entityID attribute
    if (entityDescriptor.getEntityID() != null) {
        domElement.setAttributeNS(null, EntityDescriptor.ENTITY_ID_ATTRIB_NAME, entityDescriptor.getEntityID());
    }

    // Set the ID attribute
    if (entityDescriptor.getID() != null) {
        domElement.setAttributeNS(null, EntityDescriptor.ID_ATTRIB_NAME, entityDescriptor.getID());
        domElement.setIdAttributeNS(null, EntityDescriptor.ID_ATTRIB_NAME, true);
    }

    // Set the validUntil attribute
    if (entityDescriptor.getValidUntil() != null) {
        log.debug("Writting validUntil attribute to EntityDescriptor DOM element");
        String validUntilStr = Configuration.getSAMLDateFormatter().print(entityDescriptor.getValidUntil());
        domElement.setAttributeNS(null, TimeBoundSAMLObject.VALID_UNTIL_ATTRIB_NAME, validUntilStr);
    }

    // Set the cacheDuration attribute
    if (entityDescriptor.getCacheDuration() != null) {
        log.debug("Writting cacheDuration attribute to EntityDescriptor DOM element");
        String cacheDuration = XMLHelper.longToDuration(entityDescriptor.getCacheDuration());
        domElement.setAttributeNS(null, CacheableSAMLObject.CACHE_DURATION_ATTRIB_NAME, cacheDuration);
    }

    Attr attribute;
    for (Entry<QName, String> entry : entityDescriptor.getUnknownAttributes().entrySet()) {
        attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
        attribute.setValue(entry.getValue());
        domElement.setAttributeNodeNS(attribute);
        if (Configuration.isIDAttribute(entry.getKey())
                || entityDescriptor.getUnknownAttributes().isIDAttribute(entry.getKey())) {
            attribute.getOwnerElement().setIdAttributeNode(attribute, true);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:EntityDescriptorMarshaller.java

示例12: writeAttribute

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
 * @param namespaceURI {@inheritDoc}
 * @param localName {@inheritDoc}
 * @param value {@inheritDoc}
 * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
 */
public void writeAttribute(String namespaceURI,String localName,String value)throws XMLStreamException {
    if(currentNode.getNodeType() == Node.ELEMENT_NODE){
        String prefix = null;
        if(namespaceURI == null ){
            throw new XMLStreamException("NamespaceURI cannot be null");
        }
        if(localName == null){
            throw new XMLStreamException("Local name cannot be null");
        }
        if(namespaceContext != null){
            prefix = namespaceContext.getPrefix(namespaceURI);
        }

        if(prefix == null){
            throw new XMLStreamException("Namespace URI "+namespaceURI +
                    "is not bound to any prefix" );
        }

        String qualifiedName = null;
        if(prefix.equals("")){
            qualifiedName = localName;
        }else{
            qualifiedName = getQName(prefix,localName);
        }
        Attr attr = ownerDoc.createAttributeNS(namespaceURI, qualifiedName);
        attr.setValue(value);
        ((Element)currentNode).setAttributeNode(attr);
    }else{
        //Convert node type to String
        throw new IllegalStateException("Current DOM Node type  is "+ currentNode.getNodeType() +
                "and does not allow attributes to be set ");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:XMLDOMWriterImpl.java

示例13: testSetValue

import org.w3c.dom.Attr; //导入方法依赖的package包/类
@Test
public void testSetValue() throws Exception {
    Document document = createDOM("Attr01.xml");
    Attr attr = document.createAttribute("newAttribute");
    attr.setValue("newVal");
    assertEquals(attr.getValue(), "newVal");

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:AttrTest.java

示例14: marshallAttributes

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Marshalls the <code>xs:anyAttribute</code> attributes.
 * 
 * {@inheritDoc}
 */
protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException {
    AttributeExtensibleXMLObject anyAttribute = (AttributeExtensibleXMLObject) xmlObject;
    Attr attribute;
    Document document = domElement.getOwnerDocument();
    for (Entry<QName, String> entry : anyAttribute.getUnknownAttributes().entrySet()) {
        attribute = XMLHelper.constructAttribute(document, entry.getKey());
        attribute.setValue(entry.getValue());
        domElement.setAttributeNodeNS(attribute);
        if (Configuration.isIDAttribute(entry.getKey())
                || anyAttribute.getUnknownAttributes().isIDAttribute(entry.getKey())) {
            attribute.getOwnerElement().setIdAttributeNode(attribute, true);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:AbstractExtensibleXMLObjectMarshaller.java

示例15: marshallAttributes

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void marshallAttributes(XMLObject samlElement, Element domElement) {
    Endpoint endpoint = (Endpoint) samlElement;

    if (endpoint.getBinding() != null) {
        domElement.setAttributeNS(null, Endpoint.BINDING_ATTRIB_NAME, endpoint.getBinding().toString());
    }
    if (endpoint.getLocation() != null) {
        domElement.setAttributeNS(null, Endpoint.LOCATION_ATTRIB_NAME, endpoint.getLocation().toString());
    }

    if (endpoint.getResponseLocation() != null) {
        domElement.setAttributeNS(null, Endpoint.RESPONSE_LOCATION_ATTRIB_NAME, endpoint.getResponseLocation()
                .toString());
    }

    Attr attribute;
    for (Entry<QName, String> entry : endpoint.getUnknownAttributes().entrySet()) {
        attribute = XMLHelper.constructAttribute(domElement.getOwnerDocument(), entry.getKey());
        attribute.setValue(entry.getValue());
        domElement.setAttributeNodeNS(attribute);
        if (Configuration.isIDAttribute(entry.getKey())
                || endpoint.getUnknownAttributes().isIDAttribute(entry.getKey())) {
            attribute.getOwnerElement().setIdAttributeNode(attribute, true);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:EndpointMarshaller.java


注:本文中的org.w3c.dom.Attr.setValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。