470,568 Members | 1,535 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,568 developers. It's quick & easy.

Why the XML node is saved differently ?

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>
------
Thanks
Sharon
Aug 17 '06 #1
15 1782


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?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 17 '06 #2
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>

--
Thanks
Sharon
Aug 17 '06 #3


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()
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 17 '06 #4
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

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

Aug 18 '06 #5
Of course, you are both right, the problrm is there ehrn the
m_DataSet.GetXml() is invoked.
But this is not solving my problem.
I still need to know how make the node to be saved on all computers as:

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

And not 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>
-------
Thanks
Sharon
Aug 20 '06 #6
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.)

Aug 21 '06 #7
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?
-------
Thanks
Sharon
Aug 21 '06 #8
It's look like the IXmlSerializable is only at .NET framework 2.0, but I'm
using the 1.1.
--
Thanks
Sharon
Aug 21 '06 #9
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
Sharon
Aug 21 '06 #10
Hi Sharon,

Here are some code samples for IXmlSerializable.

http://www.devx.com/dotnet/Article/29720/1763

http://www.developerfusion.co.uk/show/4639/

HTH.

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

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

Aug 22 '06 #11
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
Sharon
Aug 24 '06 #12
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
Sharon
Aug 24 '06 #13
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
Sharon
Aug 24 '06 #14
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
Sharon
Aug 24 '06 #15
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.)

Aug 25 '06 #16

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by pillepop2003 | last post: by
2 posts views Thread by Urs Vogel | last post: by
4 posts views Thread by Keith Patrick | last post: by
3 posts views Thread by gregmcmullinjr | last post: by
4 posts views Thread by agda.karlberg | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.