|
Help with what exactly? Reading XML, generating a menu, or all of it?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Preferably all of it.
I know, how to read a XML-file, but I cant display the data as a menu.
So I don't know the connection of these things ...
|
|
|
|
|
Member 13100573 wrote: Preferably all of it. In that case you'd be asking for a developer for hire.
Member 13100573 wrote: I know, how to read a XML-file, but I cant display the data as a menu. Creating a menu dynamically isn't that hard in WinForms, so I would expect it not to be too hard in WPF either. You could search for an example and give it a try - if you get stuck and have a specific question we can help.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Deserialize the XML document to a collection of say Menu objects. Then do the necessary binding to reflect what you want in the view.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"
|
|
|
|
|
And what, exactly, do you want to happen when the user clicks on a menu item? If you want to know how to construct the menu itself, search for articles on MVVM menus with WPF.
This space for rent
|
|
|
|
|
You should start to read about XmlDataProvider and how to use bindings to XML-documents with XPath.
A good starting point can be How to: Bind to XML Data Using an XMLDataProvider and XPath Queries | Microsoft Docs[^]
In the example a ListBox is populated but you should be able to replace it with a Menu bound to an XmlDataProvider as ItemsSource with a customized ItemContainerStyle that sets the Header of the MenuItem to the title attribute.
Good luck.
|
|
|
|
|
i want to shutdown remote pc connected in LAn network through by using their pcname ,,how can i do in c# help me plz?
|
|
|
|
|
Read this[^], and use the Process class to execute.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I can't seem to figure this out. Tried searching but didn't know what to call the first date format.
If it ain't broke don't fix it
|
|
|
|
|
Is it an int or a string ?
Integer:
int input = 20171005;
int year = Math.DivRem(input, 10000, out input);
int month = Math.DivRem(input, 100, out input);
DateTime dt = new DateTime(year, month, input); String:
string input = "20171005";
DateTime dt = DateTime.ParseExact(input, "yyyyMMdd", CultureInfo.InvariantCulture);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It's a string. I didn't think that DateParse would translate that string. hmm
I did examples of Date Parse, but I didn't know what my input format was called.
I'll give it a shot, Thanks Richard!
If it ain't broke don't fix it
|
|
|
|
|
|
string date1 = $"{DateTime.Now:MM/dd/yyyy}";
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
That looks interesting.
Actually my final output model is string for the date.
I'm gonna look into this.
If it ain't broke don't fix it
|
|
|
|
|
I have an XML file that I'm pulling data in and out of some lines are nothing more than crlf
<KEY FIELDID="451">
</KEY>
The property in the POCO class is structured like this
[XmlText]
public string Value { set; get; }
I can serialize the file and 451 comes back empty or when I save it saves as empty
<KEY FIELDID="451" />
I can update it to "\r\n" and it puts it back in the saved file.
var returned = MyType.Load("D:\\Sample.xml");
returned.AddUpdate(451,"\r\n");
MyType.Save(returned,"D:\\Output.xml");
Other Records with \r\n in them with additional data work with no problems
|
|
|
|
|
Not sure what you are talking about.
You have a 'element' which has a name of 'KEY'. The value of that element is some whitespace.
The element also has an 'attribute'. And the attribute name is 'FIELDID' with a value of '451'.
The element and attribute are not the same.
Without knowing the actual usage of the element (not attribute) I cannot speak to the value of it but certainly if you want a specific value then you must set it.
End of line characters shouldn't be in an attribute at all, so presumably you are referring to the element.
But an element that has nothing but whitespace, especially when it is named 'KEY' should be irrelevant and not needed.
So in summary.
1. If you want to change the value of the element then set it.
2. If you want to change the value of the attribute then set that (different than 1) and do not attempt to be end of line characters in it.
|
|
|
|
|
Let me try this again then. The item in question is not a whitespace it is a crlf which is needed by a separate app. (Yea I know, don't ask)
The XML file has a series of Key Elements each element has a FieldID and a value
<KEY FIELDID="72">TX</KEY>
I have my serializer working great except for the instances where the value is a crlf
<KEY FIELDID="451">
</KEY>
In this instance the serializer strips out the crlf and returns an null value.
I have other Keys that have data like
<pre> <KEY FIELDID="510">This one works
Really well
</KEY>
I'm having trouble understanding why the one with just a crlf comes back null and the multi line works fine. My Ultimate question is there a parameter/markup I need to add so that the crlf line works like the multi line.
I am reasonably new to XML most of my career I've worked heavily with Databases and only ever had to read output from a service and save it as xml. so this is out side of my wheelhouse.
|
|
|
|
|
XML and white-space don't generally work well together:
2.10 White Space Handling | Extensible Markup Language (XML) 1.1[^]
Unfortunately, the usual workarounds don't seem to apply to XML deserialization. Adding xml:space="preserve" , or passing in an XmlReader set to not ignore white-space, makes no difference to the result.
The only way I can see for you to preserve the white-space in an empty node is to use a CDATA element:
<KEY FIELDID="1"><![CDATA[</KEY>
[Serializable]
[XmlType("KEY")]
public class KeyType
{
[XmlAttribute("FIELDID")]
public int FieldId { set; get; }
[XmlText]
public string Value { set; get; }
[XmlElement("")]
public XmlCDataSection Content
{
get
{
return new XmlDocument().CreateCDataSection(Value);
}
set
{
if (value == null)
{
Value = null;
}
else
{
Value = value.Value;
}
}
}
}
c# - How do you serialize a string as CDATA using XmlSerializer? - Stack Overflow[^]
NB: ALL white-space within the CDATA element will be returned. So if your XML is:
<DATA>
<KEY FIELDID="1"><![CDATA[</KEY>
</DATA> your content will include the white-space at the start of the next line. If you wanted just the line break, the closing ]]> would need to be the first thing on the line, with no indentation.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well crap that is not the answer I was looking for. again its not whitespace it is literally a crlf. Perhaps XML treats it the same. Just wanted to make sure I was clear. Our current reader / writer is almost 200 lines of code that is unbelievably slow. If I can get over that one hurdle I can replace it with 10 poco classes and this method
public static MyType Load(string filename)
{
var ser = new XmlSerializer(typeof(MyType));
var returned = (MyType)ser.Deserialize(new FileStream(filename, FileMode.Open));
return returned;
}
Guess its time to get the other Guy to test my output and see if it breaks his app, if not I'm good. I was trying to open an existing file and save it as an exact match with the exception of
<Key FIELDID="123"></Key>
becoming
<Key FIELDID="123"/>
Thanks again for all your help.
If I have to keep the crlf in the file and find a way I'll post it here
I can't be the only moron to ever need to do this
|
|
|
|
|
C. David Johnson wrote: its not whitespace it is literally a crlf
CrLf is white-space!
Whitespace character - Wikipedia[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
C. David Johnson wrote: Well crap that is not the answer I was looking for
Presumably you are not passing the xml data but rather a string.
So once you have the string use string (not xml) insertion to add the whitespace.
And ALSO add a comment both in the xml handling code and the string insertion code to explain why you are doing that.
|
|
|
|
|
FIELDID is an "attribute" and you need to tag it as such; e.g.
[System.Xml.Serialization.XmlAttributeAttribute()]
public ushort FIELDID { get; set; }
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi,
In this value, 1.0, I want to compare the 0 value. While the code works if the value is 1.5, I am able to compare 5, i am not able to do the same with 0.
This works:: Convert.ToDouble(1.5).ToString().Split('.')[1]; I get a 5 value.
But this does not work :Convert.ToDouble(1.0).ToString().Split('.')[1]; I get an error message, out of bounds.
any ideas?
thanks.
|
|
|
|
|
You need to use a format string which produces a fixed number of decimal places - for example, "F3" .
Standard Numeric Format Strings | Microsoft Docs[^]
You'll also need to use the invariant culture, in case the current culture uses a different decimal separator.
string s = value.ToString("F3", CultureInfo.InvariantCulture).Split('.')[1];
But if you explain what you're actually trying to achieve, there's probably a better way to do it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Don't use compound statements like the above, and assume that they will do what you want. As you can see they often do not. In your case (double)1.0.ToString() produces the simple string "1". Which, if you had split the statement into its constituent parts you would have seen immediately.
I am not sure what actual problem you are trying to solve here but I suspect there are much simpler mathematical ways to do it.
|
|
|
|