On Apr 21, 2004, at 5:33 PM, Alberto Massari wrote:
At 11.47 21/04/2004 -0400, Nick Bastin wrote:When writing out documents which have schemas and namespaces, am I supposed to set up the createDocument() and createElement() calls differently, or just add the attributes myself?
For example, what code would I need to create:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ndr:Template xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ndr="http://www.opnet.com/ns/NetDoctor" xsi:schemaLocation="http://www.opnet.com/ns/NetDoctor /schemas/Report_Template?v11">
<...tags...>
</ndr:Template>
I can read this file successfully, but I'm not having a lot of luck writing it. Now, I'm assuming that I'm not supposed to write those attributes in directly, so maybe that's my problem. Basically, the question leads to - is there a lot of builtin support for writing documents with schemas and namespaces, or do you just call createElement with tags that already have their namespace qualifier in the name (like "ndr:Template"), or do you call it with "Template" and you've already told it a namespace?
The choice is up to you: you can use createElement("ndr:Template), but you also need to place the namespace definitions using setAttribute("xmlns:ndr","http://www.opnet.com/ns/NetDoctor"); or you use the DOM L2 API createElementNS("http://www.opnet.com/ns/NetDoctor", "ndr:Template") and the DOMWriter that will serialize it will create the (hopefully) right namespace declarations for you.
So I noticed this, but I don't *quite* understand it. You still have to put a fully-qualified name in createElementNS, so what's the point of calling it all the time? Obviously you need to call it once, so that you get the xmlns:ndr="foo" attribute on the correct node, but every child of that node should probably, for efficiency, be called using createElement(). Or am I missing something? I.e., if I create my document node with the right namespace (presuming it is used in the entire document), is there any reason to call createElementNS for the child nodes? It seems that it would save both memory and time to just call createElement(), but I may not have a full understanding of the side-effects.
-- Nick
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
