Empty XmlElements creating new line

Z

Zief

Hi,

I am having a strange problem that is probably very easy to correct.
This is using the Compact Framework for Windows Mobile if that makes
any difference.

I am changing some text of an XmlNode that has some data, to "". The
original line in the file looks like:
<Movement_Date>26/10/2006</Movement_Date>

When I set aNode.InnerXml = "" I would expect:
<Movement_Date />
but instead I get:
<Movement_Date>
</Movement_Date>

later when this is read by a different program, it picks up the
carriage return, and not null data, and therefore generates an error.
I have also tried aNode.InnerXml = string.Empty and
aNode.RemoveAll();

with the same results. I assume it is just a setting somewhere, but I
can't find where?

Zief
 
M

Morten Wennevik

Hi Zief,

There is nothing in your code that should introduce a carriage return,
though don't know what happens in Compact Framework. The expected value
should be <Movement_Date></Movement_Date>. Are you sure the carriage
return is introduced here and not later on by some formatting of the xml?
 
M

Martin Honnen

Zief said:
I am changing some text of an XmlNode that has some data, to "". The
original line in the file looks like:
<Movement_Date>26/10/2006</Movement_Date>

When I set aNode.InnerXml = "" I would expect:
<Movement_Date />
but instead I get:
<Movement_Date>
</Movement_Date>

Does it help if you set IsEmpty as well e.g.
aNode.InnerText = "";
aNode.IsEmpty = true;
?

If that does not help then set e.g.
xmlDocumentInstance.PreserveWhitespace = true
before you load or save the XML.
 
Z

Zief

Unfortunately there is no 'IsEmpty' option on the Compact Framework for
XmlNode. Under SchemaInfo there is an IsNil, but as I would suspect
with the IsEmpty property, it is read-only. I have also tried setting
PreserveWhitespace to true, and this hasn't changed its behaviour.
I am finding this behaviour very strange indeed. Do you have any more
suggestions?

Thanks,
Zief
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top