I've got a question about DOM programming I wanted to check for an upcoming
article on using Java document models. It's not strictly XercesJ, but that's the
implementation I'm using.

The code needs to create a new element ("text") with the same namespace as an
existing element ("element"). Here's the code I came up with:

  Document doc = element.getOwnerDocument();
  String prefix = element.getPrefix();
  String uri = element.getNamespaceURI();
  Element text;
  if (prefix == null) {
      text = doc.createElement("text");
  } else {
      text = doc.createElementNS(element.getNamespaceURI(),
          prefix + ":text");
  }

Is there a simpler way to do this that I'm missing?

Thanks for any pointers,

  - Dennis


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to