|
i'm trying to do what you said but i'm really new to this so it takes a while to make it. Now i have my xml file and i have a xsl file that looks like this:
<xsl:stylesheet version="1.0">
<xsl:output method="text"/>
<xsl:template match="libraries">
<xsl:apply-templates>
<xsl:sort select="loadorder"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
is this any good? how do i call this now in c#?
thx in advance
|
|
|
|
|
i think i got it
XslTransform test = new XslTransform();<br />
test.Load(@"c:\xslt.xsl");<br />
test.Transform(@"c:\file",@"c:\file2");
if forgot to say that it's not possible to just have a xsl-file because my program has to work on different computers
|
|
|
|
|
The XSLT Transform is handled completely by the .NET Framework so it will work on different computers, you just need to either use a file that you deploy with your application - using it from the Application.StartupPath or something - or embed it as a resource, get the stream using Assembly.GetManifestResourceStream , and load a Stream into both your XmlDocument (or XmlDataDocument , which works hand-in-hand with a DataSet nicely) and your XslTransform and then transform it using an appropriate Transform method. Note, the method you're currently using (with those parameters) is obsolete in .NET 1.1, so I suggest you see the documentation for the Transform Method[^] in the .NET Framework SDK for more information. If you use non-obsolete classes, members, etc. in your 1.0 application, it could be made to run under .NET 1.1 if 1.0 was not installed on a client machine.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i'm doing it now like this:
string xsl = "<xsl:stylesheet version=\"1.0\">" + "<xsl:output method=\"text\"/> " +
"<xsl:template match=\"//libraries\"> " +
" <xsl:apply-templates>"+
"<xsl:sort select=\"//loadorder\"/>"+
"</xsl:apply-templates>"+
"</xsl:template>"+
"</xsl:stylesheet>";
StreamWriter sw = File.CreateText(@"c:\xslt.xsl");
sw.WriteLine(xsl);
sw.Close();
XslTransform test = new XslTransform();
test.Load(@"c:\xslt.xsl");
test.Transform(@"c:\sessions.conf.xml",@"c:\sorted.xml");
but i'm getting a error (on the transform):
An unhandled exception of type 'System.Xml.XmlException' occurred in system.xml.dll
Additional information: System error.
|
|
|
|
|
You didn't declare the XML namespace for the "xsl" prefix in your stylesheet.
Also - like I mentioned - you don't need to save your XSLT to a file. You can save it to a stream and not have to worry about access permissions (the user may not be able to write files to the C:\ directory - besides, you should actually use Path.GetTempPath to get the user's TEMP directory).
It is better to create your XSLT as part of your application (as a project file) and set the Build Action to "Embedded Resource"). Then you only need to do something like this:
using (Stream s =
this.GetType().Assembly.GetManifestResourceStream("MyRootNamespace.File.xslt"))
{
if (s != null)
{
XslTransform xsl = new XslTransform();
xsl.Load(s);
XmlDocument xml = new XmlDocument();
xml.Load();
xsl.Transform(xml, Path.Combine(Path.GetTempPath(), "Output.xml"));
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thx for your help and sorry to disturb you again but with the code you gave ma i get some mistakes i don't know
<br />
The best overloaded method match for 'System.Xml.Xsl.XslTransform.Load(System.Xml.XmlReader)' has some invalid arguments<br />
Argument '1': cannot convert from 'System.IO.Stream' to 'System.Xml.XmlReader'<br />
<br />
The best overloaded method match for 'System.Xml.Xsl.XslTransform.Transform(System.Xml.XPath.IXPathNavigable, System.Xml.Xsl.XsltArgumentList)' has some invalid arguments<br />
Argument '2': cannot convert from 'string' to 'System.Xml.Xsl.XsltArgumentList'
|
|
|
|
|
It's because it was an example written very quickly and it's easy to solve if you look at the documentation for the XslTransform.Load method:
Stream s = this.GetType().Assembly.GetManifestResourceStream(
"MyRootNamespace.MyTransform.xslt");
XmlReader reader = new XmlTextReader(s);
XmlWriter writer = new XmlTextWriter(
Path.Combine(Path.GetTempPath(), "Output.xml"),
Encoding.UTF8);
xsl.Transform(xml, null, writer);
writer.Close();
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i just can't make it work it's getting very frustrating
i tried it now it what seems the most easy way to me:
string filePath = @"c:\nodes.xml";
string filePath2 = @"c:\XSL2.xsl";
XslTransform trans = new XslTransform();
trans.Load(filePath2);
trans.Transform(filePath,@"c:\ert.xml");
the xml file looks like this:
<sessie name="handel">
<libraries>
<library name="contxtlib">
<fullname>123</fullname>
<super>false</super>
<loadorder>1</loadorder>
</library>
<library name="xmllib">
<fullname>xmllib.p</fullname>
<super>true</super>
<loadorder>6</loadorder>
</library>
<library name="Librarytest">
<fullname>Test 44444444444</fullname>
<super>false</super>
<loadorder>5</loadorder>
</library>
<library name="vbnc">
<fullname>bvcn</fullname>
<super>true</super>
<loadorder>3</loadorder>
</library>
</libraries>
</sessie>
and the XSL looks like this:
<xsl:stylesheet version="1.0">
<xsl:output method="text"/>
<xsl:template match="//libraries">
<xsl:apply-templates>
<xsl:sort select="/library/loadorder"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
and it just won't work
|
|
|
|
|
never mind what i said, i give up
i'm just going to use a dataview and sort it like that
thx a lot for your help
|
|
|
|
|
Okay, the situation is this: I saved a Bitmap using the Bitmap.Save method into a MemoryStream and then I used the MemoryStream.ToArray() method to turn it into a Byte[] array. I used a Socket to send the the Byte[] (buffer) and recieved the buffer in a remote side (Mostly on a Pocket PC), I cannot seem to find a way to return that Byte[] back to a Bitmap, I tried using the MemoryStream(Byte[]) constructor in order to save it on a memory stream, and then using the Bitmap(System.IO.Stream) constructor but it returns an exception stating that it is an invalid parameter or argument, I would thank all who could help me solve this problem, here's an example of what I have been doing to send and recieve my Bitmap:
//Sending:
Bitmap bmp = new Bitmap(@openDialog1.FileName);
System.IO.MemoryStream memImage = new MemoryStream();
bmp.Save(memImage,System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] data = memImage.ToArray();
IPEndPoint endPoint = new IPEndPoint(this.theIP,651); //this.theIP = my IP
socket.Connect(endPoint);
socket.Send(data,0,data.Length,SocketFlags.None);
//Recieving
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("..my Ip.."),651);
this.socket.Bind(endPoint);
this.socket.Listen(10);
Socket connected = socket.Accept();
byte[] byteResponse = new byte[1024];
connected.Receive(byteResponse,SocketFlags.None);
MemoryStream memory = new MemoryStream(byteResponse);
Bitmap bmp = new Bitmap(memory); //generates invalid argument exception
this.pictureBox1.Image = bmp;
Could anyone help me and also point out my errors here, I would be a great help, thanks in advanced.
P.S. I really would prefer a method that would work in the Compact Framework, since I am working with a Pocket PC as a reciever.
|
|
|
|
|
Hi Gakujin,
To construct an image object (in your case a Bitmap, which is derived from Image) from a MemoryStream object use the Image.FromStream static method.
so simply replace:
Bitmap bmp = new Bitmap(memory);
with
Image img = Image.FromStream(memory);
I am not sure about the compact framework, but I presume loading from a stream should work, since you can save to a stream already.
EDIT: Sorry I didn't notice that the Bitmap constructor already does this, so ignore me 
|
|
|
|
|
Yes, you would have to use the Bitmap constructor since Image.FromStream is not supported on .NET CF. Just FYI
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi, it's possible to include files such ini and dll into a exe as resource???
thanks
Paolo
|
|
|
|
|
You can include every file as a resource, and read it with manifest stream:
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(namespace.filename.ini);
|
|
|
|
|
sorry for this stupid question.....and for adding a resource? in VS C++ 6.0 that wass add resource.....here where I found? thanks
|
|
|
|
|
In VS.NET it is
- project's context menu
- add existing element
- choose the file
- the file appears in the project tree
- file's context menu
- properties
- build action = embedded resource
The menu titles can be different in your visual studio, because I have only the german version 
|
|
|
|
|
|
I'm not able to write the Assembly stream to file, I've done so
<br />
private void ExtractDLL()<br />
{<br />
<br />
try<br />
{<br />
FileStream sf = new FileStream("config.ini",FileMode.Create);<br />
StreamWriter sw = new StreamWriter(sf);<br />
Stream prova = Assembly.GetExecutingAssembly().GetManifestResourceStream("config.ini");<br />
<br />
sw.Write(prova);<br />
}<br />
<br />
catch (IOException e)<br />
{<br />
MessageBox.Show("Error while accessing to resources -> " + e.Message);<br />
return;<br />
}<br />
}<br />
but I get a 0 byte file.... where I'm wrong??? thanks
Paolo
|
|
|
|
|
You must include the full qualified path of the ressource. The ressource is a part of your assembly, so the namespace belongs to its name:
<br />
Stream prova = Assembly.GetExecutingAssembly().GetManifestResourceStream("yourNamespace.config.ini");<br />
|
|
|
|
|
I'm trying to do this;
I ask;
Console.Writeline("Enter Amount");
Then I enter something like 500.10
and then I get a return value of;
"Five hundred dollars and ten cents"
What is the easiest way to do this?
Thank you for any help..
Karie
karie4@comcast.net
|
|
|
|
|
Hi Karie,
Using simple logic you can generate the desired result. I am not aware of any ready made class and function in .Net, especially dedicated for this sort of problem.
Regards,
Jay.
|
|
|
|
|
Sounds like homework to me!
RageInTheMachine9532
|
|
|
|
|
2.ToString() Shame on you!
KTB wrote that
|
|
|
|
|
A word map and simple subtraction would do, but I agree with Dave that this sounds like homework.
You can get some help, though. See my article, Custom String Formatting in .NET[^], for an example that does something similar to what you need to convert numbers to Roman numerals.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm going to add "Undo" "Redo" function for my project. But I really have no idea to do such things.
Is there any examples for this? Could anyone provide some for me??
Thanks a lot
|
|
|
|