![字体变小](http://internazional.blog.hexun.com/img/xiao.gif)
![字体变大](http://internazional.blog.hexun.com/img/da.gif)
这两天都在处理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"