|
Hello,
I have a xml-file where some words are in uppercase. Is it possible to edit the entire file. So everything in the file is in lowercase?
thx in advance
|
|
|
|
|
Read the entire file into a String, just like any text file, then call the .ToLower method on the String, then write the new file out to a DIFFERENT file. Write it out a different file just to make sure nothing went wrong and you still have the original file to work from.
RageInTheMachine9532
|
|
|
|
|
While the two previous answers tell you how, I want to stress the "why and why not". If the XML elements and attributes are supposed to be a certain case, you should leave them. XML elements and attributes are case-sensitive. Changing them would cause any processors specific to that schema (like an XSLT or DOM parser) to fail (at least, identifying it as the appropriate doc type).
If this is a file you have created, then you must make sure that any processing is changed to use the lower-case elements and attributes.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi
why output of this code isn't Transparent.
Bitmap b = new Bitmap(100,20);<br />
Graphics g = Graphics.FromImage(b);<br />
g.Clear(Color.Transparent);<br />
g.DrawString("Test",new Font("Tahoma",8),new SolidBrush(Color.Green),0,0);<br />
b.Save("test.gif",System.Drawing.Imaging.ImageFormat.Gif);<br />
Close();<br />
thanks.
|
|
|
|
|
A GIF is an index image, so there is no transparent color. There is, however, a color that is masked so that the GIF appears transparent. See the Bitmap.MakeTransparent method. You provide it a color and that image is saved with that color's index marked as the transparent color so it appears transparent when displayed.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi i am trying to get the value of an attribute displayed, but i can't seem to find the best way to get to it. If the element contains no attributes it returns -1?
XmlDocument document = new XmlDocument();<br />
document.Load("..\\..\\commands.xml");<br />
<br />
XmlNodeReader reader = new XmlNodeReader(document);<br />
<br />
this.Show();<br />
<br />
while (reader.Read())<br />
{<br />
switch (reader.NodeType)<br />
{<br />
case XmlNodeType.Element:<br />
int attributes = reader.AttributeCount;<br />
cmdOutput.Text += "<" + reader.Name + reader.GetAttribute(attributes) + ">";<br />
break;<br />
case XmlNodeType.Text:<br />
cmdOutput.Text += "\t" + reader.Value + "\r\n";<br />
break;<br />
case XmlNodeType.EndElement:<br />
cmdOutput.Text += "</" + reader.Name + ">\r\n";<br />
break;<br />
}<br />
}
|
|
|
|
|
Why not just have a case for the XmlNodeType.Attribute ? Your switch cases will be called appropriately so even if you were to just write-out the attribute, it will happen in between XmlNodeType.Element and XmlNodeType.Text or XmlNodeType.EndElement , if there are any attributes. What you have anyway will not work anyway. AttributeCount - 1 would be the index of the last attribute. Remember that indexes in the .NET FCL are 0-based.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
Is there a way to sort an xml with xslt faster? Right now a file with 15 records takes about 9 seconds. A file with 60 records takes about 15 seconds. I probably won't have more then 60 records but a file with 1000 records takes about 2 minutes. 15 seconds is still a little to long i think, is it possible to make it faster?
Thx in advance
|
|
|
|
|
How is the sorting being done? Through code you wrote or through an for-each order-by?
RageInTheMachine9532
|
|
|
|
|
Hi,
i did it like this:
private void SortXml(string sortOrder, string sortString)
{
xml.Load(filePath);
string pad = "//session[@name='" + cboSessions.SelectedItem.ToString() + "']";
XmlNodeList selectedNode = xml.SelectNodes(pad);
string box = selectedNode.Item(0).OuterXml;
xml.LoadXml(box);
XmlTextWriter xmltw = new XmlTextWriter(hulpfilePath,new UTF8Encoding(false));
xml.WriteTo(xmltw);
xmltw.Close();
string xsl = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"
+ "<xsl:template match=\"@*|node()\">"
+ "<xsl:copy>"
+ " <xsl:apply-templates select=\"@*|node()\">"
+ "<xsl:sort data-type=\"number\"" + " select=\""+ sortString +"\"" + " order=\"" + sortOrder + "\"" + "/>"
+ "</xsl:apply-templates>"
+ "</xsl:copy>"
+ "</xsl:template>"
+ "</xsl:stylesheet>";
XslTransform xslt = new XslTransform();
StringReader rdr = new StringReader(xsl);
xslt.Load(new XPathDocument(rdr), null,null);
xslt.Transform(hulpfilePath,hulpfilePath,null);
ds.Clear();
ds.ReadXml(hulpfilePath);
File.Delete(hulpfilePath);
}
|
|
|
|
|
Since your having an XSL stylesheet do the sorting for you, there isn't really a way to get a significant speed increase. The only thing I can think of trying is loading the XML document and writing the sort yourself, shuffling around nodes using you own sort algorithm. But I don't know if your going to get the kind of performance your looking for. You could only try it and see.
I haven't had the cause to sort an XML file myself. I usually just get the data I need and have the visual control sort it as needed.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Nome
|
|
|
|
|
i did it like appelz did it
thx for the help
|
|
|
|
|
Hello,
I want to open a file for my program. I'm doing it with the openfiledialog but my file can also be on a server. How can i get that file then? Is it possible?
thx in advance
|
|
|
|
|
OpenFileDialog Op=new OpenFileDialog();
Op.ShowDialog();
System.Diagnostics.Process.Start(Op.FileName.ToString());
Sreejith S S Nair
|
|
|
|
|
It depends on how you can access that server. If you access the file through a UNC, the OpenFileDialog can do that and most classes in the .NET FCL can use UNC paths. If it's an HTTP path, the OpenFileDialog can reference the file if you have the HTTP server in your Network Locations "directory", but most classes that deal with files won't be able to access it. You'd have to use a WebClient or something to download it first.
One agnostics way would be to use a WebRequest to request the file using the file path. If it's a local or UNC file path, a FileWebRequest is returned. If it's an HTTP URL, an HttpWebRequest is returned.
Really, though - you don't need to care. WebRequest.GetResponse returns a WebResponse which you can use to "download" (copy to local) the file and then you can work on it however you want. The WebRequest /WebResponse classes are pluggable protocols, and you can find out more information about them in the .NET Framework SDK under the System.Net namespace.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Hi,
I have a dll. I want to know the functions inside the dll. I don't have documentation about it. I there any way to know that.
Karteek
|
|
|
|
|
If it is an unmanaged DLL, I don't think there is anyway to find out. If it is managed, you can always decompile it - using, for example, the .net reflector[^]
|
|
|
|
|
You could use the Depends tool that comes with Visual Studio 6 to get the function names (possibly!), but not the parameters that those functions use. On top of that, without the documentation, there is no way your going to know what those functions are used for and how to properly use them.
RageInTheMachine9532
|
|
|
|
|
Hi!
I would like to show a progess-window while a hardware-reading process blocks the running threat.
I tried to intercommunicate with
ProcessStartInfo startInfo =
new processStartInfo("Animation.exe");
startInfo.FileName=@"c:\animation.exe";
startInfo.UseShellExecute=false;
startInfo.RedirectStandardInput=true;
Process Anima=Process.Start(startInfo);
...
Anima.StandardInput.WriteLine("1");
But how can I read the Standard Input in a WinForm?
Or am I on a bad track?
Thanks
Ariadne
|
|
|
|
|
First you have to redirect the StandardOutput:
startInfo.RedirectStandardOutput=true;
Then you can read the output stream just like any test file stream, for example:
String outText = Anima.StandardOuput.ReadToEnd();
RageInTheMachine9532
|
|
|
|
|
Dave thank you,
but that is not my question.
My Question: How do I write in Animation.exe (WinForms-App) to the standard output-stream?
|
|
|
|
|
That is what you asked...
But how can I read the Standard Input in a WinForm?
You can't read the StandardInput. It's a one way pipe for input TO the application you launched. You have to read the StandardOutput to see what the application wrote to the screen.
RageInTheMachine9532
|
|
|
|
|
Yes that's the point: I want change the animation from the parent app.
Ie:
MyApp -> (starts) -> Animation.exe (starts)
later
MyApp -> (command) -> Animation.exe (change picture)
later
MyApp -> (kill) -> Animation.exe (ends)
I tought, I can use a Standard IO-Pipe to command Animation.exe to change it's picture. But I do not know, how to receive the command in Animation.exe
|
|
|
|
|
???????????????????????????????????????????????
???????????????????????????????????????????????
???????????????????????????????????????????????
I take it Animation.exe is a commandline utility that runs in a CMD window? Correct?
If Animation.exe is a normal Windows app (GUI interface), then this won't work...
You can "talk" to Animation.exe through the Standard pipes. StandardInput is the keyboard stream into Animation.exe and StandardOutput is the console stream that the app uses to display text. If you redirect both of these streams in the ProcessStart class you used, you can read and write to the streams using .StardardInput.WriteLine() and .StandardOutput.ReadLine() on the process object that is returned. The catch is, if you redirect the streams, the user won't see anything except a blank console window. No text will be displayed and the window won't respond to the keyboard. Your app will have to send keyboard input using .WriteLine() just like the user would type at the keyboard. If the user has to type EXIT to get the app to quit, your app would have to do something like p.StandardInput.WriteLine("EXIT") to do the same.
RageInTheMachine9532
|
|
|
|