Why the XML node is saved differently ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an XML question:

I'm have an XML node of type PointF and when it's saved to a file by
XmlDocument.Save(...) it saves as I expect it to be saved:

<ImageOrigin>{X=1.2, Y=3.4}</ImageOrigin>


But on my boss laptop this XML node is saved as:

<ImageOrigin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<X>1.2</X>
<Y>3.4</Y>
</ImageOrigin>

And it make my code to fail.


Does anybody can tell why the difference?
What should I do so the node will be saved on all computers as:
<ImageOrigin>{X=1.2, Y=3.4}</ImageOrigin>
 
Sharon wrote:

I'm have an XML node of type PointF and when it's saved to a file by
XmlDocument.Save(...) it saves as I expect it to be saved:

<ImageOrigin>{X=1.2, Y=3.4}</ImageOrigin>


But on my boss laptop this XML node is saved as:

<ImageOrigin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<X>1.2</X>
<Y>3.4</Y>
</ImageOrigin>

XmlNodeType in System.Xml knows node types like Element or Attribute or
Text but certainly not PointF.
I think you need to explain in some more detail what you are doing. Is
PointF a .NET type you have declared? If so how does the type
declaration look? Do you use an XSD schema to define a type PointF? If
so how does the type declaration look? How do you create the nodes in
the XML document? Are you trying to use the XML serialization features
in .NET?
 
Ok, you are right. so here it is:

I have a XML schema (XSD), and a derived DataSet that is created using this
XML schema.
To this DataSet I'm adding column:
m_DataSet.Tables["MyTableName"].Columns.Add("ImageOrigin", typeof(PointF));

Later n in the code this column gets a value of type PointF.

This DataSet content is saved to a file like this:

-------------------------------------
m_DataSet.AcceptChanges();
string xmlDB = m_DataSet.GetXml();
XmlDocument doc = new XmlDocument();
doc.LoadXml( xmlDB );
doc.Save("DbFile.xml");
-------------------------------------

And all the computers I'm using the saved file are OK with the ImageOrigin
node that saved like this:

<ImageOrigin>{X=1.2, Y=3.4}</ImageOrigin>

But on my boss laptop this XML node is saved as:

<ImageOrigin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<X>1.2</X>
<Y>3.4</Y>
</ImageOrigin>

And it make my code to fail.


Why this difference?
What should I do so the node will be saved on all computers as:

<ImageOrigin>{X=1.2, Y=3.4}</ImageOrigin>
 
Sharon wrote:

This DataSet content is saved to a file like this:

-------------------------------------
m_DataSet.AcceptChanges();
string xmlDB = m_DataSet.GetXml();
XmlDocument doc = new XmlDocument();
doc.LoadXml( xmlDB );
doc.Save("DbFile.xml");

But then I don't think the Save method of the XmlDocument is creating
the difference, I am pretty sure the difference is already there when
you get the string of XML from the dataset:
string xmlDB = m_DataSet.GetXml()
 
Hi Sharon,

I agree with Martin. Also you can use m_DataSet.WriteXml("DbFile.xml");
directly? Will this give you the same output for a point object?

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi Sharon,

You have to inherit the IXmlSerializable class to make this happen. In the
WriteXml method of IXmlSerializable, you can control how the object data is
output.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Thanks Kevin, can you post some example or forward me to one?

I still do not understand why the difference exist? is it the XML parser
version or what?
 
Sorry, my mistake. The IXmlSerializable is supported by the 1.1 Frameworks.

But implementing the WriteXml() for all the derived DataSet is not that
trivial.
 
Thanks for your post and email.
There is too much work to implement the WriteXml() of the IXmlSerializable,
the DataSet structure is not that simple.
Furthermore, I'm writing a library function that should return a string
containing the DataSet content in a XML format.
I guess that maybe the XML parser version is different in that specific
laptop, so for now I added the following code when saving the string it to a
file:

// Anyhow I need the XmlDocument for another peace of code out of our scope.
XmlDocument doc = new XmlDocument();
doc.LoadXml( m_filterHandler.GetXmlDB() );
XmlNode node = doc.SelectSingleNode(".../ImageOrigin");
if( node != null && node.ChildNodes.Count == 2 )
{ // In case the pontF is in the unwanted format <ImageOrigin
....><X>1.2</X><Y>3.4</Y></ImageOrigin>
node.RemoveAll();
node.InnerXml = ptf.ToString(); // will make it: <ImageOrigin>{X=1.2,
Y=3.4}</ImageOrigin>
}
..... // some other peace of code out of our scope.
doc.Save("MyFileName.xml");

This fix does the job.
But still; I do not know why the difference exists as I already described in
my previous post. Do you ???
 
Thanks for your post and email.
There is too much work do for implement the WriteXml() of the
IXmlSerializable, the DataSet structure is not that simple.
Furthermore, I'm writing a library function that should return a string
containing the DataSet content in a XML format.
I guess that maybe the XML parser version is different in the specific
laptop, so for now I have added the following code when saving the string to
a file:

PointF ptf = new Pointf(1.2, 3.4);
// Anyhow I need the XmlDocument for another peace of code out of our scope.
XmlDocument doc = new XmlDocument();
doc.LoadXml( m_dataSet.GetXmlDB() );
XmlNode node = doc.SelectSingleNode(".../ImageOrigin");
if( node != null && node.ChildNodes.Count == 2 )
{ // In case the pointF is in the unwanted format: <ImageOrigin
....><X>1.2</X><Y>3.4</Y></ImageOrigin>
node.RemoveAll();
node.InnerXml = ptf.ToString(); // will make it: <ImageOrigin>{X=1.2,
Y=3.4}</ImageOrigin>
}
..... // some other peace of code out of our scope.
doc.Save("MyFileName.xml");

This fix does the job.

But still; I do not know why the difference exists as I already described in
my previous post. Do you ???
 
Thanks for your post and email.
There is too much work do for implement the WriteXml() of the IXmlSerializable, the DataSet structure is not that simple.
Furthermore, I'm writing a library function that should return a string containing the DataSet content in a XML format.
I guess that maybe the XML parser version is different in the specific laptop, so for now I have added the following code when saving the string to a file:

PointF ptf = new Pointf(1.2, 3.4);
// Anyhow I need the XmlDocument for another peace of code out of our scope.
XmlDocument doc = new XmlDocument();
doc.LoadXml( m_dataSet.GetXmlDB() );
XmlNode node = doc.SelectSingleNode(".../ImageOrigin");
if( node != null && node.ChildNodes.Count == 2 )
{ // In case the pointF is in the unwanted format: <ImageOrigin ....><X>1.2</X><Y>3.4</Y></ImageOrigin>
node.RemoveAll();
node.InnerXml = ptf.ToString(); // will make it: <ImageOrigin>{X=1.2, Y=3.4}</ImageOrigin>
}
..... // some other peace of code out of our scope.
doc.Save("MyFileName.xml");

This fix does the job.

But still; I do not know why the difference exists as I already described in my previous post. Do you ???
 
Thanks for your post and email.
There is too much work do for implement the WriteXml() of the IXmlSerializable, the DataSet structure is not that simple.
Furthermore, I'm writing a library function that should return a string containing the DataSet content in a XML format.
I guess that maybe the XML parser version is different in the specific laptop, so for now I have added the following code when saving the string to a file:

PointF ptf = new Pointf(1.2, 3.4);
// Anyhow I need the XmlDocument for another peace of code out of our scope.
XmlDocument doc = new XmlDocument();
doc.LoadXml( m_dataSet.GetXmlDB() );
XmlNode node = doc.SelectSingleNode(".../ImageOrigin");
if( node != null && node.ChildNodes.Count == 2 )
{ // In case the pointF is in the unwanted format: <ImageOrigin ....><X>1.2</X><Y>3.4</Y></ImageOrigin>
node.RemoveAll();
node.InnerXml = ptf.ToString(); // will make it: <ImageOrigin>{X=1.2, Y=3.4}</ImageOrigin>
}
..... // some other peace of code out of our scope.
doc.Save("MyFileName.xml");

This fix does the job.

But still; I do not know why the difference exists as I already described in my previous post. Do you ???
 
Hi Sharon,

I'm sorry, since I didn't reproduced this on my machine, I don't know how
this happens, either. Anyway, it was nice to know that you have had a
workaround to this problem. If you have any questions, please feel free to
post them int eh community.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top