C# ReadXML with Rectangle The Next CEO of Stack OverflowHow do I read and parse an XML file in C#?How to serialize/deserialize simple classes to XML and backHow do I deserialize this XML back into an array of Point objectsWhat is the difference between String and string in C#?Hidden Features of C#?Cast int to enum in C#How do I enumerate an enum in C#?What are the correct version numbers for C#?How to get rid of the xmlns when using xml serializationXmlSerializer obfuscation support?Cloning an instance of object to its base typexsd.exe: generate class for old schema (http://www.w3.org/2000/10/XMLSchema)Add Namespace to an xml root node c#
Does int main() need a declaration on C++?
Incomplete cube
What difference does it make matching a word with/without a trailing whitespace?
Is this a new Fibonacci Identity?
How can the PCs determine if an item is a phylactery?
Are British MPs missing the point, with these 'Indicative Votes'?
Find a path from s to t using as few red nodes as possible
What is the difference between 'contrib' and 'non-free' packages repositories?
Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico
Prodigo = pro + ago?
Is a distribution that is normal, but highly skewed, considered Gaussian?
Gauss' Posthumous Publications?
Is it reasonable to ask other researchers to send me their previous grant applications?
Was the Stack Exchange "Happy April Fools" page fitting with the 90s code?
Is a linearly independent set whose span is dense a Schauder basis?
logical reads on global temp table, but not on session-level temp table
How to pronounce fünf in 45
Why can't we say "I have been having a dog"?
How to find if SQL server backup is encrypted with TDE without restoring the backup
Can a PhD from a non-TU9 German university become a professor in a TU9 university?
Arrows in tikz Markov chain diagram overlap
Can Sri Krishna be called 'a person'?
Is it "common practice in Fourier transform spectroscopy to multiply the measured interferogram by an apodizing function"? If so, why?
What steps are necessary to read a Modern SSD in Medieval Europe?
C# ReadXML with Rectangle
The Next CEO of Stack OverflowHow do I read and parse an XML file in C#?How to serialize/deserialize simple classes to XML and backHow do I deserialize this XML back into an array of Point objectsWhat is the difference between String and string in C#?Hidden Features of C#?Cast int to enum in C#How do I enumerate an enum in C#?What are the correct version numbers for C#?How to get rid of the xmlns when using xml serializationXmlSerializer obfuscation support?Cloning an instance of object to its base typexsd.exe: generate class for old schema (http://www.w3.org/2000/10/XMLSchema)Add Namespace to an xml root node c#
I have a dataset, "AllEventData", and in that dataset is (for the moment) only one table called buttonData. It has 3 columns - an autoincrementing number primary key, a name (typeof(string)), and a rectangle. The third column is specifically typeof(Rectangle). I display it all with a datatablepanel.
I did the AllEventData.WriteXML method to write the file with no special parameters, and that seems to work fine - I get a file that looks like this:
<?xml version="1.0" standalone="yes"?>
<AllEventData>
<ButtonData>
<ID>1</ID>
<Button_x0020_Name>sdfh</Button_x0020_Name>
<Button_x005F_x0020_Location xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Location>
<X>480</X>
<Y>186</Y>
</Location>
<Size>
<Width>95</Width>
<Height>67</Height>
</Size>
<X>480</X>
<Y>186</Y>
<Width>95</Width>
<Height>67</Height>
</Button_x005F_x0020_Location>
</ButtonData>
</AllEventData>
But when I do a AllEventData.ReadXML of the same file, it only fills the datatablepanel with the button names, not the rectangle locations.
I tried doing a write of the schema separately:
using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
*.xml";
saveFileDialog1.Title = "Save File";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
AllEventData.WriteXml(saveFileDialog1.FileName);
string xsdFileName = saveFileDialog1.FileName.Substring(0, saveFileDialog1.FileName.Length - 3) + "xsd";
AllEventData.WriteXmlSchema(xsdFileName);
and the same basic thing in reverse to read it with a schema:
using (OpenFileDialog openFileDialog1 = new OpenFileDialog())
*.xml";
openFileDialog1.Title = "Open File";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
AllEventData.Clear();
string xsdFileName = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.Length - 3) + "xsd";
AllEventData.ReadXmlSchema(xsdFileName);
AllEventData.ReadXml(openFileDialog1.FileName);
But still not getting there.
Why isn't ReadXML working to read what WriteXML wrote?
c# readxml
|
show 5 more comments
I have a dataset, "AllEventData", and in that dataset is (for the moment) only one table called buttonData. It has 3 columns - an autoincrementing number primary key, a name (typeof(string)), and a rectangle. The third column is specifically typeof(Rectangle). I display it all with a datatablepanel.
I did the AllEventData.WriteXML method to write the file with no special parameters, and that seems to work fine - I get a file that looks like this:
<?xml version="1.0" standalone="yes"?>
<AllEventData>
<ButtonData>
<ID>1</ID>
<Button_x0020_Name>sdfh</Button_x0020_Name>
<Button_x005F_x0020_Location xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Location>
<X>480</X>
<Y>186</Y>
</Location>
<Size>
<Width>95</Width>
<Height>67</Height>
</Size>
<X>480</X>
<Y>186</Y>
<Width>95</Width>
<Height>67</Height>
</Button_x005F_x0020_Location>
</ButtonData>
</AllEventData>
But when I do a AllEventData.ReadXML of the same file, it only fills the datatablepanel with the button names, not the rectangle locations.
I tried doing a write of the schema separately:
using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
*.xml";
saveFileDialog1.Title = "Save File";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
AllEventData.WriteXml(saveFileDialog1.FileName);
string xsdFileName = saveFileDialog1.FileName.Substring(0, saveFileDialog1.FileName.Length - 3) + "xsd";
AllEventData.WriteXmlSchema(xsdFileName);
and the same basic thing in reverse to read it with a schema:
using (OpenFileDialog openFileDialog1 = new OpenFileDialog())
*.xml";
openFileDialog1.Title = "Open File";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
AllEventData.Clear();
string xsdFileName = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.Length - 3) + "xsd";
AllEventData.ReadXmlSchema(xsdFileName);
AllEventData.ReadXml(openFileDialog1.FileName);
But still not getting there.
Why isn't ReadXML working to read what WriteXML wrote?
c# readxml
1
what isAllEventData
?
– Daniel A. White
Mar 21 at 20:10
1
How do I read and parse an XML file in C#?.
– Olivier Jacot-Descombes
Mar 21 at 20:12
@DanielA.White, the dataset.
– TulsaNewbie
Mar 21 at 20:13
2
XML does not have the notion of a Rectangle. As this XML is, you will have to read the values, and create a rectangle out of themnew Rectangle(x, y, width, height)
. Or maybe you should use aXmlSerializer
. See: How to serialize/deserialize simple classes to XML and back.
– Olivier Jacot-Descombes
Mar 21 at 20:43
1
XML itself knows only primitive types like string, boolean or decimal and nested tags. But XML serializers/deserializers can cope with complex types. A completely different approach would be to use WPF which uses a specialized XML called XAML to create visible UI elements.
– Olivier Jacot-Descombes
Mar 22 at 13:23
|
show 5 more comments
I have a dataset, "AllEventData", and in that dataset is (for the moment) only one table called buttonData. It has 3 columns - an autoincrementing number primary key, a name (typeof(string)), and a rectangle. The third column is specifically typeof(Rectangle). I display it all with a datatablepanel.
I did the AllEventData.WriteXML method to write the file with no special parameters, and that seems to work fine - I get a file that looks like this:
<?xml version="1.0" standalone="yes"?>
<AllEventData>
<ButtonData>
<ID>1</ID>
<Button_x0020_Name>sdfh</Button_x0020_Name>
<Button_x005F_x0020_Location xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Location>
<X>480</X>
<Y>186</Y>
</Location>
<Size>
<Width>95</Width>
<Height>67</Height>
</Size>
<X>480</X>
<Y>186</Y>
<Width>95</Width>
<Height>67</Height>
</Button_x005F_x0020_Location>
</ButtonData>
</AllEventData>
But when I do a AllEventData.ReadXML of the same file, it only fills the datatablepanel with the button names, not the rectangle locations.
I tried doing a write of the schema separately:
using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
*.xml";
saveFileDialog1.Title = "Save File";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
AllEventData.WriteXml(saveFileDialog1.FileName);
string xsdFileName = saveFileDialog1.FileName.Substring(0, saveFileDialog1.FileName.Length - 3) + "xsd";
AllEventData.WriteXmlSchema(xsdFileName);
and the same basic thing in reverse to read it with a schema:
using (OpenFileDialog openFileDialog1 = new OpenFileDialog())
*.xml";
openFileDialog1.Title = "Open File";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
AllEventData.Clear();
string xsdFileName = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.Length - 3) + "xsd";
AllEventData.ReadXmlSchema(xsdFileName);
AllEventData.ReadXml(openFileDialog1.FileName);
But still not getting there.
Why isn't ReadXML working to read what WriteXML wrote?
c# readxml
I have a dataset, "AllEventData", and in that dataset is (for the moment) only one table called buttonData. It has 3 columns - an autoincrementing number primary key, a name (typeof(string)), and a rectangle. The third column is specifically typeof(Rectangle). I display it all with a datatablepanel.
I did the AllEventData.WriteXML method to write the file with no special parameters, and that seems to work fine - I get a file that looks like this:
<?xml version="1.0" standalone="yes"?>
<AllEventData>
<ButtonData>
<ID>1</ID>
<Button_x0020_Name>sdfh</Button_x0020_Name>
<Button_x005F_x0020_Location xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Location>
<X>480</X>
<Y>186</Y>
</Location>
<Size>
<Width>95</Width>
<Height>67</Height>
</Size>
<X>480</X>
<Y>186</Y>
<Width>95</Width>
<Height>67</Height>
</Button_x005F_x0020_Location>
</ButtonData>
</AllEventData>
But when I do a AllEventData.ReadXML of the same file, it only fills the datatablepanel with the button names, not the rectangle locations.
I tried doing a write of the schema separately:
using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
*.xml";
saveFileDialog1.Title = "Save File";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
AllEventData.WriteXml(saveFileDialog1.FileName);
string xsdFileName = saveFileDialog1.FileName.Substring(0, saveFileDialog1.FileName.Length - 3) + "xsd";
AllEventData.WriteXmlSchema(xsdFileName);
and the same basic thing in reverse to read it with a schema:
using (OpenFileDialog openFileDialog1 = new OpenFileDialog())
*.xml";
openFileDialog1.Title = "Open File";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
AllEventData.Clear();
string xsdFileName = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.Length - 3) + "xsd";
AllEventData.ReadXmlSchema(xsdFileName);
AllEventData.ReadXml(openFileDialog1.FileName);
But still not getting there.
Why isn't ReadXML working to read what WriteXML wrote?
c# readxml
c# readxml
edited Mar 22 at 14:51
TulsaNewbie
asked Mar 21 at 20:06
TulsaNewbieTulsaNewbie
597
597
1
what isAllEventData
?
– Daniel A. White
Mar 21 at 20:10
1
How do I read and parse an XML file in C#?.
– Olivier Jacot-Descombes
Mar 21 at 20:12
@DanielA.White, the dataset.
– TulsaNewbie
Mar 21 at 20:13
2
XML does not have the notion of a Rectangle. As this XML is, you will have to read the values, and create a rectangle out of themnew Rectangle(x, y, width, height)
. Or maybe you should use aXmlSerializer
. See: How to serialize/deserialize simple classes to XML and back.
– Olivier Jacot-Descombes
Mar 21 at 20:43
1
XML itself knows only primitive types like string, boolean or decimal and nested tags. But XML serializers/deserializers can cope with complex types. A completely different approach would be to use WPF which uses a specialized XML called XAML to create visible UI elements.
– Olivier Jacot-Descombes
Mar 22 at 13:23
|
show 5 more comments
1
what isAllEventData
?
– Daniel A. White
Mar 21 at 20:10
1
How do I read and parse an XML file in C#?.
– Olivier Jacot-Descombes
Mar 21 at 20:12
@DanielA.White, the dataset.
– TulsaNewbie
Mar 21 at 20:13
2
XML does not have the notion of a Rectangle. As this XML is, you will have to read the values, and create a rectangle out of themnew Rectangle(x, y, width, height)
. Or maybe you should use aXmlSerializer
. See: How to serialize/deserialize simple classes to XML and back.
– Olivier Jacot-Descombes
Mar 21 at 20:43
1
XML itself knows only primitive types like string, boolean or decimal and nested tags. But XML serializers/deserializers can cope with complex types. A completely different approach would be to use WPF which uses a specialized XML called XAML to create visible UI elements.
– Olivier Jacot-Descombes
Mar 22 at 13:23
1
1
what is
AllEventData
?– Daniel A. White
Mar 21 at 20:10
what is
AllEventData
?– Daniel A. White
Mar 21 at 20:10
1
1
How do I read and parse an XML file in C#?.
– Olivier Jacot-Descombes
Mar 21 at 20:12
How do I read and parse an XML file in C#?.
– Olivier Jacot-Descombes
Mar 21 at 20:12
@DanielA.White, the dataset.
– TulsaNewbie
Mar 21 at 20:13
@DanielA.White, the dataset.
– TulsaNewbie
Mar 21 at 20:13
2
2
XML does not have the notion of a Rectangle. As this XML is, you will have to read the values, and create a rectangle out of them
new Rectangle(x, y, width, height)
. Or maybe you should use a XmlSerializer
. See: How to serialize/deserialize simple classes to XML and back.– Olivier Jacot-Descombes
Mar 21 at 20:43
XML does not have the notion of a Rectangle. As this XML is, you will have to read the values, and create a rectangle out of them
new Rectangle(x, y, width, height)
. Or maybe you should use a XmlSerializer
. See: How to serialize/deserialize simple classes to XML and back.– Olivier Jacot-Descombes
Mar 21 at 20:43
1
1
XML itself knows only primitive types like string, boolean or decimal and nested tags. But XML serializers/deserializers can cope with complex types. A completely different approach would be to use WPF which uses a specialized XML called XAML to create visible UI elements.
– Olivier Jacot-Descombes
Mar 22 at 13:23
XML itself knows only primitive types like string, boolean or decimal and nested tags. But XML serializers/deserializers can cope with complex types. A completely different approach would be to use WPF which uses a specialized XML called XAML to create visible UI elements.
– Olivier Jacot-Descombes
Mar 22 at 13:23
|
show 5 more comments
1 Answer
1
active
oldest
votes
As Olivier notes in the comments, rectangles too complex for XML even though it can break them down and look like it's going to work just fine. There's no way it'll ever read it, even with schema, the same way it writes it. So the "trick" to reading it properly is to either:
- Write a code block to parse the XML as noted in the "how to parse xml" link
- Serialize and deserialize the rectangle as noted in the "how to serialize/deserialize" link
- Store the data completely differently in the table in the first place.
The latter was what I ultimately chose to do. It's really easy for me to extract the X, Y, Width, and Height from the rectangle and store those in individual columns of the table (which also let me store another piece of data I was trying to figure out how to add in), and then turn them back into rectangles later when I need them, and it makes editing the rectangles easier for the user to figure out, too.
Doing that, I'm able to simply AllEventData.WriteXML and AllEventData.ReadXML with no further code.
add a comment |
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288501%2fc-sharp-readxml-with-rectangle%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As Olivier notes in the comments, rectangles too complex for XML even though it can break them down and look like it's going to work just fine. There's no way it'll ever read it, even with schema, the same way it writes it. So the "trick" to reading it properly is to either:
- Write a code block to parse the XML as noted in the "how to parse xml" link
- Serialize and deserialize the rectangle as noted in the "how to serialize/deserialize" link
- Store the data completely differently in the table in the first place.
The latter was what I ultimately chose to do. It's really easy for me to extract the X, Y, Width, and Height from the rectangle and store those in individual columns of the table (which also let me store another piece of data I was trying to figure out how to add in), and then turn them back into rectangles later when I need them, and it makes editing the rectangles easier for the user to figure out, too.
Doing that, I'm able to simply AllEventData.WriteXML and AllEventData.ReadXML with no further code.
add a comment |
As Olivier notes in the comments, rectangles too complex for XML even though it can break them down and look like it's going to work just fine. There's no way it'll ever read it, even with schema, the same way it writes it. So the "trick" to reading it properly is to either:
- Write a code block to parse the XML as noted in the "how to parse xml" link
- Serialize and deserialize the rectangle as noted in the "how to serialize/deserialize" link
- Store the data completely differently in the table in the first place.
The latter was what I ultimately chose to do. It's really easy for me to extract the X, Y, Width, and Height from the rectangle and store those in individual columns of the table (which also let me store another piece of data I was trying to figure out how to add in), and then turn them back into rectangles later when I need them, and it makes editing the rectangles easier for the user to figure out, too.
Doing that, I'm able to simply AllEventData.WriteXML and AllEventData.ReadXML with no further code.
add a comment |
As Olivier notes in the comments, rectangles too complex for XML even though it can break them down and look like it's going to work just fine. There's no way it'll ever read it, even with schema, the same way it writes it. So the "trick" to reading it properly is to either:
- Write a code block to parse the XML as noted in the "how to parse xml" link
- Serialize and deserialize the rectangle as noted in the "how to serialize/deserialize" link
- Store the data completely differently in the table in the first place.
The latter was what I ultimately chose to do. It's really easy for me to extract the X, Y, Width, and Height from the rectangle and store those in individual columns of the table (which also let me store another piece of data I was trying to figure out how to add in), and then turn them back into rectangles later when I need them, and it makes editing the rectangles easier for the user to figure out, too.
Doing that, I'm able to simply AllEventData.WriteXML and AllEventData.ReadXML with no further code.
As Olivier notes in the comments, rectangles too complex for XML even though it can break them down and look like it's going to work just fine. There's no way it'll ever read it, even with schema, the same way it writes it. So the "trick" to reading it properly is to either:
- Write a code block to parse the XML as noted in the "how to parse xml" link
- Serialize and deserialize the rectangle as noted in the "how to serialize/deserialize" link
- Store the data completely differently in the table in the first place.
The latter was what I ultimately chose to do. It's really easy for me to extract the X, Y, Width, and Height from the rectangle and store those in individual columns of the table (which also let me store another piece of data I was trying to figure out how to add in), and then turn them back into rectangles later when I need them, and it makes editing the rectangles easier for the user to figure out, too.
Doing that, I'm able to simply AllEventData.WriteXML and AllEventData.ReadXML with no further code.
answered Mar 22 at 14:52
TulsaNewbieTulsaNewbie
597
597
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288501%2fc-sharp-readxml-with-rectangle%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
what is
AllEventData
?– Daniel A. White
Mar 21 at 20:10
1
How do I read and parse an XML file in C#?.
– Olivier Jacot-Descombes
Mar 21 at 20:12
@DanielA.White, the dataset.
– TulsaNewbie
Mar 21 at 20:13
2
XML does not have the notion of a Rectangle. As this XML is, you will have to read the values, and create a rectangle out of them
new Rectangle(x, y, width, height)
. Or maybe you should use aXmlSerializer
. See: How to serialize/deserialize simple classes to XML and back.– Olivier Jacot-Descombes
Mar 21 at 20:43
1
XML itself knows only primitive types like string, boolean or decimal and nested tags. But XML serializers/deserializers can cope with complex types. A completely different approach would be to use WPF which uses a specialized XML called XAML to create visible UI elements.
– Olivier Jacot-Descombes
Mar 22 at 13:23