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


Java Element.setPrefix方法代码示例

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


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

示例1: fixupPrefix

import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
 * Ensure (recursively) children prefix is same as parent if same namespace.
 * To be used when adding newcomponent subtree to this component.
 */
private void fixupPrefix(C newComponent) {
   if (getModel().inSync() || getModel().inUndoRedo()) return;
    
    AbstractDocumentComponent child = (AbstractDocumentComponent) newComponent;
    Element e = child.getPeer();
    String childNS = child.getNamespaceURI();
    if (childNS == null || childNS.equals(XMLConstants.NULL_NS_URI)) {
        return;
    }
   
    if (childNS.equals(getNamespaceURI())) {
        e.setPrefix(getPeer().getPrefix());
    } else if (childNS.equals(lookupNamespaceURI(""))) {
        e.setPrefix(null);
    } else {
        ensurePrefixDeclaredFor(e, childNS);
    }

    for (C c : newComponent.getChildren()) {
        fixupPrefix(c);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AbstractDocumentComponent.java

示例2: XmlDocument

import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
 * Converts the given technical products to a dom document.
 * 
 * @param techProds
 *            the technical products to convert
 * @param localizer
 *            the localizer used to read localized values
 * @param dm
 *            the data service used to read other values
 * @return the dom document
 */
public XmlDocument(String namespace, String namespacePrefix,
        String schemaLocation, String rootNodeName) {

    set(namespace, namespacePrefix, schemaLocation, rootNodeName);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new SaaSSystemException(e);
    }

    xmldoc = builder.getDOMImplementation().createDocument(getNameSpace(),
            getRootNodeName(), null);
    root = (Element) xmldoc.getFirstChild();
    root.setPrefix(getPrefix());
    root.setAttribute("xmlns:xsi",
            "http://www.w3.org/2001/XMLSchema-instance");
    root.setAttribute("xsi:schemaLocation", getSchemaLocation());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:32,代码来源:XmlDocument.java

示例3: addWsdLDocumentation

import org.w3c.dom.Element; //导入方法依赖的package包/类
private static void addWsdLDocumentation(Definition definition, WSDLElement wsdlElement, String documentation) {
if (documentation.equals(""))
	return;

  	try {
	Document doc = new WSDLWriterImpl().getDocument(definition);
	Element element = doc.createElementNS("http://schemas.xmlsoap.org/wsdl/","documentation");
	element.setPrefix("wsdl");
	String cdataValue = documentation;
	cdataValue = cdataValue.replaceAll("<!\\[CDATA\\[", "&lt;!\\[CDATA\\[");
	cdataValue = cdataValue.replaceAll("\\]\\]>", "\\]\\]&gt;");
	element.appendChild(doc.createCDATASection(cdataValue));
	wsdlElement.setDocumentationElement(element);
} catch (WSDLException e) {
	e.printStackTrace();
}
  }
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:18,代码来源:WebServiceServlet.java

示例4: ensurePrefixDeclaredFor

import org.w3c.dom.Element; //导入方法依赖的package包/类
private void ensurePrefixDeclaredFor(Element newComponentElement, String newComponentNS) {
    String existingPrefix = lookupPrefix(newComponentNS);
    String prefix = newComponentElement.getPrefix();
    if (existingPrefix == null) {
        if (prefix == null) {
            prefix = "ns"; //NOI18N
        }
        prefix = ensureUnique(prefix, newComponentNS);
        ((AbstractDocumentComponent)getModel().getRootComponent()).
                addPrefix(prefix, newComponentNS);
        newComponentElement.setPrefix(prefix);
    } else {
        newComponentElement.setPrefix(existingPrefix);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:AbstractDocumentComponent.java

示例5: marshallNamespacePrefix

import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
 * Marshalls the namespace prefix of the XMLObject into the DOM element.
 * 
 * @param xmlObject the XMLObject being marshalled
 * @param domElement the DOM element the XMLObject is being marshalled into
 */
protected void marshallNamespacePrefix(XMLObject xmlObject, Element domElement) {
    String prefix = xmlObject.getElementQName().getPrefix();
    prefix = DatatypeHelper.safeTrimOrNullString(prefix);

    if (prefix != null) {
        domElement.setPrefix(prefix);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:AbstractXMLObjectMarshaller.java

示例6: createElement

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public DomNode createElement(DomNode parent, QName element) throws XmlBuilderException {
    try {
        final Element elem;
        if (XMLConstants.NULL_NS_URI.equals(element.getNamespaceURI())) {
            elem = document.createElement(element.getLocalPart());
        } else {
            elem = document.createElementNS(element.getNamespaceURI(), element.getLocalPart());
            elem.setPrefix(element.getPrefix());
        }
        return new DomNode(parent.getNode().appendChild(elem));
    } catch (DOMException de) {
        throw new XmlBuilderException("Unable to create element: " + element, de);
    }
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:16,代码来源:DomNavigator.java

示例7: createElement

import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
 * Static method to create a DOM element.
 * 
 * @param aDoc is the document
 * @param asNameSpaceURI is the name space for the element. Will be null for DOM level 1 elements
 * @param asLocalName is the element name
 */
public static Element createElement(Document aDoc,
                                    String asNameSpaceURI,
                                    String asLocalName) {
   Element newElem = null;
   if (asNameSpaceURI != null) {
      newElem = aDoc.createElementNS(asNameSpaceURI, asLocalName);
      // create prefix
      String[] parts = asNameSpaceURI.split("/");
      String lastPart = parts[parts.length - 1];
      String prefix;
      if ((lastPart.length() > 2) && (!lastPart.contains("."))) {
         prefix = lastPart.toLowerCase().substring(0, 3);
      }
      else {
         prefix = "tns";
      }
      int prefixSuffix = 0;
      do {
         if (prefixSuffix > 0) {
            prefix = prefix + String.valueOf(prefixSuffix);
         }
         if ((prefixTable.get(prefix) == null) || (prefixTable.get(prefix) == asNameSpaceURI)) {
            newElem.setPrefix(prefix);
            prefixTable.put(prefix, asNameSpaceURI);
            break;
         }
         else {
            prefixSuffix = prefixSuffix + 1;
         }
      }
      while (prefixTable.get(prefix) == null);
      aDoc.normalizeDocument();
   }
   else {
      newElem = aDoc.createElement(asLocalName);
   }
   return newElem;
}
 
开发者ID:mqsysadmin,项目名称:dpdirect,代码行数:46,代码来源:DocumentHelper.java

示例8: duplicateNode

import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
 * Helper method used by {@link #findAlternateToolsXml(InputStream)} to duplicate a node
 * and attach it to the given root in the new document.
 */
private Element duplicateNode(Element newRootNode, Element oldNode,
        String namespaceUri, String prefix) {
    // The implementation here is more or less equivalent to
    //
    //    newRoot.appendChild(newDoc.importNode(oldNode, deep=true))
    //
    // except we can't just use importNode() since we need to deal with the fact
    // that the old document is not namespace-aware yet the new one is.

    Document newDoc = newRootNode.getOwnerDocument();
    Element newNode = null;

    String nodeName = oldNode.getNodeName();
    int pos = nodeName.indexOf(':');
    if (pos > 0 && pos < nodeName.length() - 1) {
        nodeName = nodeName.substring(pos + 1);
        newNode = newDoc.createElementNS(namespaceUri, nodeName);
        newNode.setPrefix(prefix);
    } else {
        newNode = newDoc.createElement(nodeName);
    }

    newRootNode.appendChild(newNode);

    // Merge in all the attributes
    NamedNodeMap attrs = oldNode.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        Attr newAttr = null;

        String attrName = attr.getNodeName();
        pos = attrName.indexOf(':');
        if (pos > 0 && pos < attrName.length() - 1) {
            attrName = attrName.substring(pos + 1);
            newAttr = newDoc.createAttributeNS(namespaceUri, attrName);
            newAttr.setPrefix(prefix);
        } else {
            newAttr = newDoc.createAttribute(attrName);
        }

        newAttr.setNodeValue(attr.getNodeValue());

        if (pos > 0) {
            newNode.getAttributes().setNamedItemNS(newAttr);
        } else {
            newNode.getAttributes().setNamedItem(newAttr);
        }
    }

    // Merge all child elements and texts
    for (Node child = oldNode.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            duplicateNode(newNode, (Element) child, namespaceUri, prefix);

        } else if (child.getNodeType() == Node.TEXT_NODE) {
            Text newText = newDoc.createTextNode(child.getNodeValue());
            newNode.appendChild(newText);
        }
    }

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


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