Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

SV: [jdom-interest] Building and XML Spreadsheet for Microsoft Excel - Office XP Prof essional

Per Norrman

2003-11-13

Replies:

Hi,

Always used namespaces when creating elements. Add namespace
declarations as necessary to the root element.

For example:
-------------------------------------------------------------
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.output.XMLOutputter;

public class Excel {

 public static void main(String[] args) throws Exception {
   Namespace ns =
     Namespace.getNamespace(
 
"urn:schemas-microsoft-com:office:spreadsheet");
   Namespace o =
     Namespace.getNamespace(
       "o",
       "urn:schemas-microsoft-com:office:office");

   Element wb = new Element("Workbook", ns);
       wb.addContent(new Element("OfficeStuff", o));
       wb.addContent(new Element("ExcelStuff", ns));
   wb.addNamespaceDeclaration(o);

   new XMLOutputter("  ", true).output(new Document(wb),
System.out);

 }
}

/pmn

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.