You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by co...@gmail.com on 2006/05/01 22:01:43 UTC

Default attribute values for new XML documents

If I load an XML document from disk and that document has a DTD
reference, then my EntityResolver is used to locate the DTD. When I
ask for an attribute that doesn't exist in the XML file I correctly
get the default value specified in the DTD.

I'd like the same thing to happen for newly created documents. I am
using DOMImplementation::createDocumentType(X("myxml"), X(""),
X("myxml.dtd")); and the document correctly contains the DOCTYPE entry
but when I ask for the same attribute I'm getting nil instead of the
default value in the DTD.

Should this work? If it should, then what is the mechanism by which
the DTD is located? There is no EntityResolver associated with the new
XML document. I've tried using XercesDOMParser::loadGrammar to pre
load the DTD and cache it, but so far I haven't been able to get this
to work.

Thanks in advance!

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Default attribute values for new XML documents

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi,

coding.meister@gmail.com writes:

> The DOM specification says this about createElement
> (http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-2141741547)
>
> In addition, if there are known attributes with default values, Attr
> nodes representing them are automatically created and attached to the
> element.

The spec is actually misleading here. In some situations (e.g., XML
Schema-based validation) the "type" of the element (and thus the list
of default attributes) could only be determined after it has been
inserted into the document.

hth,
-boris
-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Default attribute values for new XML documents

Posted by Gareth Reakes <ga...@embracemobile.com>.
Hey,

	Boris is correct here. The problem is we just don't know about them. 
You could serialize to an in mem buffer and then parse/validate it, then 
you would get them.

Cheers,

Gareth

coding.meister@gmail.com wrote:
> The DOM specification says this about createElement
> (http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-2141741547)
> 
> Creates an element of the type specified. Note that the instance
> returned implements the Element interface, so attributes can be
> specified directly on the returned object.
> In addition, if there are known attributes with default values, Attr
> nodes representing them are automatically created and attached to the
> element.
> 
> I believe this means that the default attribute nodes should be
> created in the createNode implementation. Or am I misunderstanding the
> spec?
> 
> On 5/3/06, Boris Kolpackov <bo...@codesynthesis.com> wrote:
> 
>>
>> coding.meister@gmail.com writes:
>>
>> > If I load an XML document from disk and that document has a DTD
>> > reference, then my EntityResolver is used to locate the DTD. When I
>> > ask for an attribute that doesn't exist in the XML file I correctly
>> > get the default value specified in the DTD.
>> >
>> > I'd like the same thing to happen for newly created documents. I am
>> > using DOMImplementation::createDocumentType(X("myxml"), X(""),
>> > X("myxml.dtd")); and the document correctly contains the DOCTYPE entry
>> > but when I ask for the same attribute I'm getting nil instead of the
>> > default value in the DTD.
>>
>> In order for this to work the document needs to be validated
>> "on-the-fly", as you create it. This is necessary in order to
>> associate schema (DTD or XML Schema) definitions with document
>> nodes so that when you ask for an attribute that does not
>> exist, the default attribute set and their values could be
>> consulted.
>>
>> I don't think this is supported simply because if it were, we
>> would have also had in-memory validation, which is definitely
>> not supported.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
> 
> 


-- 
Gareth Reakes, Managing Director           Embrace Mobile
+44-1865-811197              http://www.embracemobile.com

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Default attribute values for new XML documents

Posted by co...@gmail.com.
The DOM specification says this about createElement
(http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-2141741547)

Creates an element of the type specified. Note that the instance
returned implements the Element interface, so attributes can be
specified directly on the returned object.
In addition, if there are known attributes with default values, Attr
nodes representing them are automatically created and attached to the
element.

I believe this means that the default attribute nodes should be
created in the createNode implementation. Or am I misunderstanding the
spec?

On 5/3/06, Boris Kolpackov <bo...@codesynthesis.com> wrote:
>
> coding.meister@gmail.com writes:
>
> > If I load an XML document from disk and that document has a DTD
> > reference, then my EntityResolver is used to locate the DTD. When I
> > ask for an attribute that doesn't exist in the XML file I correctly
> > get the default value specified in the DTD.
> >
> > I'd like the same thing to happen for newly created documents. I am
> > using DOMImplementation::createDocumentType(X("myxml"), X(""),
> > X("myxml.dtd")); and the document correctly contains the DOCTYPE entry
> > but when I ask for the same attribute I'm getting nil instead of the
> > default value in the DTD.
>
> In order for this to work the document needs to be validated
> "on-the-fly", as you create it. This is necessary in order to
> associate schema (DTD or XML Schema) definitions with document
> nodes so that when you ask for an attribute that does not
> exist, the default attribute set and their values could be
> consulted.
>
> I don't think this is supported simply because if it were, we
> would have also had in-memory validation, which is definitely
> not supported.

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Default attribute values for new XML documents

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi,

coding.meister@gmail.com writes:

> I'd like the same thing to happen for newly created documents. I am
> using DOMImplementation::createDocumentType(X("myxml"), X(""),
> X("myxml.dtd")); and the document correctly contains the DOCTYPE entry
> but when I ask for the same attribute I'm getting nil instead of the
> default value in the DTD.

In order for this to work the document needs to be validated
"on-the-fly", as you create it. This is necessary in order to
associate schema (DTD or XML Schema) definitions with document
nodes so that when you ask for an attribute that does not
exist, the default attribute set and their values could be
consulted.

I don't think this is supported simply because if it were, we
would have also had in-memory validation, which is definitely
not supported.

hth,
-boris
-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org