本文整理汇总了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);
}
}
示例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());
}
示例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\\[", "<!\\[CDATA\\[");
cdataValue = cdataValue.replaceAll("\\]\\]>", "\\]\\]>");
element.appendChild(doc.createCDATASection(cdataValue));
wsdlElement.setDocumentationElement(element);
} catch (WSDLException e) {
e.printStackTrace();
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}