本文整理汇总了Java中org.w3c.dom.Element.replaceChild方法的典型用法代码示例。如果您正苦于以下问题:Java Element.replaceChild方法的具体用法?Java Element.replaceChild怎么用?Java Element.replaceChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Element
的用法示例。
在下文中一共展示了Element.replaceChild方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFullProjectDOM
import org.w3c.dom.Element; //导入方法依赖的package包/类
public static void getFullProjectDOM(Document document,String projectName, StreamSource xslFilter) throws TransformerFactoryConfigurationError, EngineException, TransformerException{
Element root = document.getDocumentElement();
getFullProjectDOM(document,projectName);
// transformation du dom
Transformer xslt = TransformerFactory.newInstance().newTransformer(xslFilter);
Element xsl = document.createElement("xsl");
xslt.transform(new DOMSource(document), new DOMResult(xsl));
root.replaceChild(xsl.getFirstChild(), root.getFirstChild());
}
示例2: preconfigure
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public void preconfigure(Element element) throws Exception {
super.preconfigure(element);
try {
NodeList properties = element.getElementsByTagName("property");
// If needed: migration of itemtitle from MobileSmartSourceType to String (scriptable)
Element propElement = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "itemtitle");
if (propElement != null) {
Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
if (valueElement != null) {
Document document = valueElement.getOwnerDocument();
Object content = XMLUtils.readObjectFromXml(valueElement);
if (content instanceof MobileSmartSourceType) {
MobileSmartSourceType itemTitle = (MobileSmartSourceType) content;
String itemText = Mode.PLAIN.equals(itemTitle.getMode()) ? "'"+itemTitle.getSmartValue()+"'" : itemTitle.getSmartValue();
Element newValueElement = (Element)XMLUtils.writeObjectToXml(document, itemText);
propElement.replaceChild(newValueElement, valueElement);
hasChanged = true;
Engine.logBeans.warn("(UIDynamicMenuItem) 'itemtitle' has been updated for the object \"" + getName() + "\"");
}
}
}
}
catch(Exception e) {
throw new EngineException("Unable to preconfigure the menuitem component \"" + getName() + "\".", e);
}
}
示例3: preconfigure
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public void preconfigure(Element element) throws Exception {
super.preconfigure(element);
try {
long priority = new Long(element.getAttribute("priority")).longValue();
if (priority == 0L) {
priority = getNewOrderValue();
element.setAttribute("priority", ""+priority);
element.setAttribute("newPriority", ""+priority);
}
NodeList properties = element.getElementsByTagName("property");
// migration of scriptContent from String to FormatedContent
Element propElement = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "scriptContent");
if (propElement != null) {
Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
if (valueElement != null) {
Document document = valueElement.getOwnerDocument();
Object content = XMLUtils.readObjectFromXml(valueElement);
if (content instanceof String) {
FormatedContent formated = new FormatedContent((String) content);
Element newValueElement = (Element)XMLUtils.writeObjectToXml(document, formated);
propElement.replaceChild(newValueElement, valueElement);
hasChanged = true;
Engine.logBeans.warn("(PageComponent) 'scriptContent' has been updated for the object \"" + getName() + "\"");
}
}
}
}
catch(Exception e) {
throw new EngineException("Unable to preconfigure the page component \"" + getName() + "\".", e);
}
}
示例4: preconfigure
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public void preconfigure(Element element) throws Exception {
super.preconfigure(element);
try {
NodeList properties = element.getElementsByTagName("property");
// migration of styleContent from String to FormatedContent
Element propElement = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "styleContent");
if (propElement != null) {
Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
if (valueElement != null) {
Document document = valueElement.getOwnerDocument();
Object content = XMLUtils.readObjectFromXml(valueElement);
if (content instanceof String) {
FormatedContent formated = new FormatedContent((String) content);
Element newValueElement = (Element)XMLUtils.writeObjectToXml(document, formated);
propElement.replaceChild(newValueElement, valueElement);
hasChanged = true;
Engine.logBeans.warn("(UIStyle) 'styleContent' has been updated for the object \"" + getName() + "\"");
}
}
}
}
catch(Exception e) {
throw new EngineException("Unable to preconfigure the style component \"" + getName() + "\".", e);
}
}
示例5: preconfigure
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public void preconfigure(Element element) throws Exception {
super.preconfigure(element);
try {
NodeList properties = element.getElementsByTagName("property");
// migration of componentScriptContent from String to FormatedContent
Element propElement = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "componentScriptContent");
if (propElement != null) {
Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
if (valueElement != null) {
Document document = valueElement.getOwnerDocument();
Object content = XMLUtils.readObjectFromXml(valueElement);
if (content instanceof String) {
FormatedContent formated = new FormatedContent((String) content);
Element newValueElement = (Element)XMLUtils.writeObjectToXml(document, formated);
propElement.replaceChild(newValueElement, valueElement);
hasChanged = true;
Engine.logBeans.warn("(ApplicationComponent) 'componentScriptContent' has been updated for the object \"" + getName() + "\"");
}
}
}
}
catch(Exception e) {
throw new EngineException("Unable to preconfigure the application component \"" + getName() + "\".", e);
}
}
示例6: testReplaceChild
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test
public void testReplaceChild() throws Exception {
Document document = createDOM("Node04.xml");
Element parentElement = (Element) document.getElementsByTagName("to").item(0);
Element element = (Element) document.getElementsByTagName("sender").item(0);
parentElement.replaceChild(createTestDocumentFragment(document), element);
String outputfile = USER_DIR + "ReplaceChild3.out";
String goldfile = GOLDEN_DIR + "ReplaceChild3GF.out";
tryRunWithTmpPermission(() -> outputXml(document, outputfile), new PropertyPermission("user.dir", "read"));
assertTrue(compareWithGold(goldfile, outputfile));
}
示例7: testReplaceChildNeg
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test(expectedExceptions = DOMException.class)
public void testReplaceChildNeg() throws Exception {
Document document = createDOM("Node04.xml");
Document doc2 = createNewDocument();
Element parentElement = (Element) document.getElementsByTagName("to").item(0);
Element element = (Element) document.getElementsByTagName("sender").item(0);
parentElement.replaceChild(createTestDocumentFragment(doc2), element);
}
示例8: testCreateUserAccount
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* This will check if adoptNode works will adoptNode from
* @see <a href="content/userInfo.xml">userInfo.xml</a>
* @see <a href="content/accountInfo.xml">accountInfo.xml</a>. This is
* adopting a node from the XML file which is validated by a DTD and
* into an XML file which is validated by the schema This covers Row 5
* for the table
* http://javaweb.sfbay/~jsuttor/JSR206/jsr-206-html/ch03s05.html. Filed
* bug 4893745 because there was a difference in behavior.
*
* @throws Exception If any errors occur.
*/
@Test
public void testCreateUserAccount() throws Exception {
String userXmlFile = XML_DIR + "userInfo.xml";
String accountXmlFile = XML_DIR + "accountInfo.xml";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
MyErrorHandler eh = new MyErrorHandler();
docBuilder.setErrorHandler(eh);
Document document = docBuilder.parse(userXmlFile);
Element user = (Element) document.getElementsByTagName("FirstName").item(0);
// Set schema after parsing userInfo.xml. Otherwise it will conflict
// with DTD validation.
dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
DocumentBuilder docBuilder1 = dbf.newDocumentBuilder();
docBuilder1.setErrorHandler(eh);
Document accDocument = docBuilder1.parse(accountXmlFile);
Element firstName = (Element) accDocument
.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "FirstName").item(0);
Element adoptedAccount = (Element) accDocument.adoptNode(user);
Element parent = (Element) firstName.getParentNode();
parent.replaceChild(adoptedAccount, firstName);
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
MyDOMOutput mydomoutput = new MyDOMOutput();
mydomoutput.setByteStream(System.out);
writer.write(document, mydomoutput);
writer.write(accDocument, mydomoutput);
assertFalse(eh.isAnyError());
}