Convert dom4j element to w3c element

The conversion code should look something like this:

<code>*

/**
 * Convert dom4j element to w3c element
 **/
public org.w3c.Element convert( org.dom4j.Element element) {
  org.dom4j.Document doc1 = DocumentHelper.createDocument();
  doc1.setRootElement( element);


  // Convert dom4j document to w3c document

  DOMWriter writer = new DOMWriter();
  org.w3c.Document doc2 = writer.write( doc1);

  return doc2.getDocumentElement() ;
}

/**
 * Convert w3c element to dom4j element
 **/
public org.dom4j.Element convert( org.w3c.Element element) {
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();


  org.w3c.Document doc1 = builder.newDocument();
  doc1.appendChild( element); 

  
  // Convert w3c document to dom4j document
  DOMReader reader = new DOMReader();
  org.dom4j.Document doc2 = reader.read( doc1);

  return doc2.getRootElement();
}

</code>

*Code not tested.



你可能感兴趣的:(c)