Hi all,

well, I don't know exactly but maybee this is more a problem of
understanding xml in my mind then a real xerces prob, but anyway I
would be apreciate for your help.

I would like to do the following:

I have an element in an xml-doc which has an attribute with a default
value given in the dtd.
But when I parse the doc with the attribute-value given as an empty
string (like attr="") the attribute will be overwritten by the default
value! But I don't want this to happen. I thought that an attribute is
only substituted by the default when it is not present at all in the
element. Or in other words, why doesn't the parser distinguish
between an empty attribute value and the absence of the attribute at
all?

An other problem is pretty similar:
When I parse the same document I am trying to manipulate the above
mentioned attribute value, it is not possible to set it to NULL or an
empty string! What is happining is that the value is not manipulated at
all!

Well, to recapitulate: My question is
1. Is it possible to tell the parser to distinguish between an empty
attribute value and no attribute at all?
2. Is it possible to set an attribute value to an empty string or NULL?
3. If 1 & 2 are answered with no: Is this an xml probleme, a xerces
problem or my own problem ? ;-)

I would be very grateful for any help or advice and I have attached some
code snippets to explain my problems in this way.

cu
    stefan
<!ELEMENT root (child)*>

<!ELEMENT child EMPTY>
<!-- If the mentioned behavior could be achieved with xml: 
     How does this dtd has to look like? -->
<!ATTLIST child  attr CDATA "someData">


<!DOCTYPE root SYSTEM "example.dtd">
<root>
  <!-- I would like the parser to keep this! But he changes the attr=""
       to attr="someData" -->
  <child attr=""/>
</root>


#include <iostream>
#include <unistd.h>
#include <framework/LocalFileInputSource.hpp>
#include <util/PlatformUtils.hpp>
#include <parsers/DOMParser.hpp>
#include <dom/DOMString.hpp>
#include <dom/DOM_Element.hpp>

int main(void)
{

  // Please don't blame me for my coding style
  // this is just a quick hack to explain
  // my problems!
  try
    {
      XMLPlatformUtils::Initialize();
    }
  catch (...)
    {
      cout<<"Some error occured"<<endl;
      _exit(0);
    }
  DOMParser parser;

  try
    {
      parser.parse("example.xml");
    }
  catch(...)
    {
      cout<<"Some error occured"<<endl;
      _exit(0);
    }
  
  DOM_Document doc= parser.getDocument();
  DOM_NodeList childList= doc.getElementsByTagName("child");

  DOM_Node tmp=childList.item(0);
  DOM_Element child=(DOM_Element &) tmp; 

  DOM_Attr attr= child.getAttributeNode("attr");

  cout<<"This is attr before manipulation: "<<attr.getValue().transcode()<<endl;

  //!!!!This doesn't seem to work!!!!Why?
  attr.setValue("");

  cout<<"This is attr after manipulation: "<<attr.getValue().transcode()<<endl;
  
}




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

Reply via email to