Skip to main content

Creating a DOM document with namespace

No replies
jncolin
Offline
Joined: 2004-05-20
Points: 0

Hi
I'm trying to create a DOM document by adding nodes to it, and I need this document to follow an XML Schema I've defined. I would expect to have the namespaces included in the root, but I never managed to get them (although I can have them at the sub-element level).

So here's what I get:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

3.5
4.5
5.5
1265033541128

while I would like to get:
<?xml version="1.0" encoding="UTF-8"?>

0
0
-1073741773

Here's how I'm doing it
Document d = docBuilder.newDocument();
Element positionElement = d.createElement("position");
Element element;
element = d.createElement("longitude");
element.setTextContent(String.valueOf(3.5));
positionElement.appendChild(element);
element = d.createElement("latitude");
element.setTextContent(String.valueOf(4.5));
positionElement.appendChild(element);
element = d.createElement("altitude");
element.setTextContent(String.valueOf(5.5));
positionElement.appendChild(element);
element = d.createElement("timestamp");
element.setTextContent(String.valueOf(Calendar.getInstance()
.getTimeInMillis()));
positionElement.appendChild(element);
d.appendChild(positionElement);

Thanks for your help

Jean-Noel Colin