Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

Why the XML node is saved differently ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sharon - 17 Aug 2006 09:54 GMT
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
Martin Honnen - 17 Aug 2006 15:31 GMT
> 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:
[quoted text clipped - 8 lines]
>     <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?

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Sharon - 17 Aug 2006 16:01 GMT
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>

Signature

Thanks
Sharon

Martin Honnen - 17 Aug 2006 16:30 GMT
> This DataSet content is saved to a file like this:
>
[quoted text clipped - 4 lines]
> 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()

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Kevin Yu [MSFT] - 18 Aug 2006 02:32 GMT
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.)
Sharon - 20 Aug 2006 07:36 GMT
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
Kevin Yu [MSFT] - 21 Aug 2006 10:10 GMT
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.)
Sharon - 21 Aug 2006 11:35 GMT
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
Sharon - 21 Aug 2006 12:00 GMT
It's look like the IXmlSerializable is only at .NET framework 2.0, but I'm
using the 1.1.

Signature

Thanks
Sharon

Sharon - 21 Aug 2006 12:24 GMT
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.

Signature

Thanks
Sharon

Kevin Yu [MSFT] - 22 Aug 2006 07:14 GMT
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.)
Sharon - 24 Aug 2006 11:26 GMT
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
Kevin Yu [MSFT] - 25 Aug 2006 06:42 GMT
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.)
Sharon - 24 Aug 2006 11:53 GMT
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
Sharon G. - 24 Aug 2006 11:54 GMT
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
Sharon G. - 24 Aug 2006 11:54 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.