logo       

Related Msgs: audio.musicbrai...    enbd.general/20...    ietf.idr/2002-0...    java.ant-contri...    gnu.make.genera...    qplus.devel/200...    video.freevo.cv...    os.netbsd.ports...    yellowdog.gener...    xfree86.cvs/200...    search.nutch.us...    freedesktop.xse...    programming.swi...    capabilities.ge...    telephony.pbx.a...    mail.sylpheed.c...    db.firebase.por...    boot-loaders.u-...    recreation.radi...    netbsd.bugs/200...    web.zope.plone....    user-groups.lin...   

changing DOM with DTD declaration to DOM with default namespace: msg#00000

Subject: changing DOM with DTD declaration to DOM with default namespace
Dear all,

I want to convert an XML document containing a DOCTYPE declaration into
one with a default namespace (i.e. the root element should become <ODM
xmlns="http://www.cdisc.org/ns/odm/v1.2"; ...>

So, what I do is:
DocumentBuilderFactory docBuilderFactory =
DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);
Document doc = null;
try {
  DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
  doc = docBuilder.parse(xmlfile);  // xmlfile is the input XML file
} catch ...
}

doc.removeChild(doc.getDoctype());  // remove the DTD declaration
doc.getDocumentElement().setAttribute("xmlns","http://www.cdisc.org/ns/odm/v1.2";);

The last statement is known not to be correct. 
Maybe I could use: doc.createElementNS(...) to create a new root element
and then add all the attributes and child nodes of the original
document to the new element.
But isn't there a better and faster way ?

Many thanks in advance

Jozef Aerts



Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo