
这两天都在处理XSD(XML结构定义 XML Schemas Definition ),
在处理中使用了clone的方法,所以在此作一记录
List list = root.getChildren();
for(Iterator iter = list.iterator(); iter.hasNext();)
{
Element child = (Element)iter.next();
Element new_child = (Element)child.clone();
new_root.addContent(new_child);
}
root:根元素
new_root:新的根元素
child:子元素
new_child:新的子元素
Element new_child = (Element)child.clone();
创建了一个新的子元素,这个子元素没有父结点,但存在子结点。
如果:
Element new_child = child;
就会产生错误:
The Content already has an existing parent "root"
本文介绍了在处理XML结构定义(XSD)时使用clone方法的过程。通过clone创建无父节点的新子元素,避免了已存在父节点的问题。
21万+

被折叠的 条评论
为什么被折叠?



