Connecting Tech Pros Worldwide Forums | Help | Site Map

Empty XmlElements creating new line

Zief
Guest
 
Posts: n/a
#1: Nov 2 '06
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


Morten Wennevik
Guest
 
Posts: n/a
#2: Nov 2 '06

re: Empty XmlElements creating new line


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?


On Thu, 02 Nov 2006 10:41:54 +0100, Zief <zieftech@gmail.comwrote:
Quote:
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
>


--
Happy Coding!
Morten Wennevik [C# MVP]
Martin Honnen
Guest
 
Posts: n/a
#3: Nov 2 '06

re: Empty XmlElements creating new line


Zief wrote:
Quote:
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.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Zief
Guest
 
Posts: n/a
#4: Nov 7 '06

re: Empty XmlElements creating new line


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

Martin Honnen wrote:
Quote:
Zief wrote:
>
Quote:
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.
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Closed Thread