|
|
I want to generate a svg using c# and DOM. I have:
<br />
XmlDocument mySvg = new XmlDocument();<br />
XmlDeclaration declaration = mySvg.CreateXmlDeclaration("1.0", "UTF-8", "no");<br />
mySvg.AppendChild(declaration);<br />
XmlDocumentType doctype = mySvg.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null);<br />
mySvg.AppendChild(doctype);<br />
The problem is that the DTD is retrieved from the internet and that gives a huge overhead to my application. I downloaded the DTD and I want to make it SYSTEM instead of PUBLIC but I haven't found a way to do this using CreateDocumentType. The only alternative I could think of is mySvg.Load(LongStringWithXML).
|
|
|
|
|
Hi,
can someone help me with replacing a value in a XML file? The whole cycle starting with the filename - i.e. load/replace/save, or however this should be done)
The value is the contents of a simple tag,
<FOO><BAR>...<BAZ>0</BAZ>...</BAR></FOO>
(I want to set the BAZ value to 1)
thanks in advance!
|
|
|
|
|
This should work:
XmlDocument xmlDoc = new XmlDocument();<br />
xmlDoc.Load( "myxml.xml" );<br />
<br />
XmlNode node = xmlDoc.SelectSingleNode( "/foo/bar/baz" );<br />
<br />
if ( node != null )<br />
{<br />
node.InnerText = "1";<br />
}<br />
<br />
xmlDoc.Save("myxml.xml");<br />
as long as there's only one baz element, otherwise you need to iterate over the nodes using SelectNodes or use xpath to determine which unique baz you want, like: xmlDoc.SelectSingleNode( "//foo/bar/baz[@id='123']" ).
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
This almost works
The document gets loaded correctly (according to the debugger) - but the selectsinglenode doesn't work.
Here's the XML:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<Extensibility xmlns="http://schemas.microsoft.com/AutomationExtensibility">
<HostApplication>
<Name>Microsoft Visual Studio Macros</Name>
<Version>8.0</Version>
</HostApplication>
<HostApplication>
<Name>Microsoft Visual Studio</Name>
<Version>8.0</Version>
</HostApplication>
<Addin>
<FriendlyName>peterchens Linkify</FriendlyName>
<Description>Link source code comments to external documentation</Description>
<AboutBoxDetails>For more information, see the respective article at codeporject.com\r\n\r\nCopyright (c) 2006 Peter Hauptmann</AboutBoxDetails>
<AboutIconData>(blubber blubber)</AboutIconData>
<Assembly>D:\Sources\C#\Linkify\bin\Linkify.dll</Assembly>
<FullClassName>Linkify.Connect</FullClassName>
<LoadBehavior>1</LoadBehavior>
<CommandPreload>1</CommandPreload>
<CommandLineSafe>0</CommandLineSafe>
</Addin>
</Extensibility>
I need the LoadBehavior and CommandPreload elements, but SelectSingleNode("/Extensibility/Addin/LoadBehavior") returns a null node. can you help?
|
|
|
|
|
Hmph. If I change the xml files encoding to "UTF-8", and remove the xmlns attribute, it works for me.
I don't know much about Unicode, so maybe you need to adjust those two attributes, or change the parameter of SelectSingleNode (again, I don't know how to tell it its unicoded).
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
<br />
XmlDocument document = new XmlDocument();<br />
document.Load("YourXML.xml"); <br />
<br />
XmlNodeList nodeList = document.SelectNodes("//BAZ");<br />
foreach (XmlNode node in nodeList)<br />
node.InnerText = "1";<br />
document.Save(".\YourXML.xml");<br />
I am sure you can work with that to enhance it (This code assumes that you have the XML file in the same folder with the executable file. It also assumes that you want to modify all the <baz> nodes values if there are more than one.)
Good luck coding
//I posted at the same time
|
|
|
|
|
|
When the BinaryWriter writes the string to the file, it does so in a format so that the string can be read again. To know how to read the string, it has to write the length of the string before the characters in the string.
If you just want to write the characters in the string, you have to do exactly as you have done; writing them as an array of characters.
I can't think of any other data type that is handled the same way, but if it can be of variable size, the size has of course be included when it's written to the stream.
---
b { font-weight: normal; }
|
|
|
|
|
|
Lord Kixdemp wrote: what kind of data is the size option? It's only 1 byte... Does that mean what the string type can only contain 256 chars?
Surely not. I am sure that it has some solution to allow longer strings. My guess is that the value 255 means that a full 32 bit length follows.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
After executing a thread method, I am getting this error,
Attempted to read and write protected memory. This is often an indication that other memory is corrupt.
Is there any way to get rid of this problem ? I am not sure which block of the code is throwing this exception.
Regards
|
|
|
|
|
bashiwala wrote: I am not sure which block of the code is throwing this exception.
The unsafe one.
Try adding some exception handling code...
|
|
|
|
|
having this error after closing a socket. immediately after closing an asynchronous socket I get this exception. vs 2005 does not show any line to debug
|
|
|
|
|
You are right. It comes just after closing asynchronous operation and no line information is given. What approach you followed to solve the problem... any idea ?
|
|
|
|
|
I'm using the color picker to allow a user to specify a background color and I want to set the text color to be the inverse.
I thought the Color object had an inverse property but it doesn't.
Does anybody know how to do this?
|
|
|
|
|
Inverse:
Color c = Color.FromArgb(255 - BackColor.R, 255 - BackColor.G, 255 - BackColor.B);
You may also want to try choosing black, or white depending on the brightness like this:
Color c = BackColor.GetBrightness() > 0.5 ? Color.Black : Color.White;
|
|
|
|
|
It's easy, but not very useful. You just make a new color from the components of the color:
Color.FromArgb(255 - color.R, 255 - color.G, 255 - color.B)
As I said, it's not very useful, as the inverse of some colors is so close to the color that you text will be unreadable. The inverse of medium gray, for example, is so close to medium gray that the text will be invisible.
---
b { font-weight: normal; }
|
|
|
|
|
i faced the same problem before
what i did was that if the diffrence between (color.r) and (255 -color.r)
is less than 50 i just add 50( approx or may be 100 i didnt remember exact) to the result color and same for g and b and result was the solution of invisiblity problem
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
In the Proramming C#;it is said:
"C++ programmers take note: you must explicitly mark the declaration of any method that overrides a virtual method with the keyword override. "
But in this Code"public override void DrawWindow( )",When I delete the override it also run fine!
And I also hope you can tell me wether this book(Programming C# Fourth Edition) is better Or the Beginning with visual C#2005?
If you guys have other wonderful books,Please recommend some to me!
|
|
|
|
|
If you don't explicitly write override before a function name, the compiler assumes that you meant to create a new function.
See also this link from MSDN[^]:
"By default, C# methods are not virtual — if a method is declared as virtual, any class inheriting the method can implement its own version. To make a method virtual, the virtual modifier is used in the method declaration of the base class. The derived class can then override the base virtual method by using the override keyword or hide the virtual method in the base class by using the new keyword. If neither the override keyword nor the new keyword is specified, the compiler will issue a warning and the method in the derived class will hide the method in the base class. For more information, see Compiler Warning CS0108[^]."
In short, the code will compile just fine (perhaps with a warning), but it might produce results that you weren't expecting. Hope this helps!
|
|
|
|
|
i need the information abt how to transfer the values from a particular file, which is in one form, to their respective text boxes which is other form
|
|
|
|
|
string content = File.ReadAllText(file) will read the contents of a file into a string .
Do whatever you want with this string then
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
Hi,
I have written a program in which I use a dll that is not .NET.
If I use the part of the program that is only .Net, it works fine. Also if I use only the part that uses the dll. BUt if I use in order the .Net part and then the dll, it gives me an AccessViolationException.
This is a MultiThreading Environment.
I modified the prog so the two part doesn't have anything in common, but it didn't help.
So those are the questions:
- Does the FrameWork move objects? So if I register an event in my dll with a reference, it can be not valid after a while?
- How can I get the memory position of an object?
This is part of the class that imports the dll:
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate void SM_MONITOR_PROC(string scanner_id, int evnt, int param);
private delegate void SM_IMAGE_PROC(string scanner_id, int width, int height, System.IntPtr ptrImg, int resolution, int param);
private delegate void SM_STATE_PROC(string scanner_id, int state, int param);
[DllImport("scanman.dll")]
private static extern int SMInitialize();
[DllImport("scanman.dll")]
private static extern int SMFinalize();
[DllImport("scanman.dll")]
private static extern int SMGetScannerCount();
[DllImport("scanman.dll")]
private static extern int SMGetScannerId(int index,System.Text.StringBuilder id, int len);
[DllImport("scanman.dll")]
private static extern int SMStartCapturing(string scanner_id, SM_IMAGE_PROC image_proc, SM_STATE_PROC state_proc, int param);
[DllImport("ssl.dll")]
private static extern int UseDirectCallbacks(int use);
[DllImport("scanman.dll")]
private static extern int SMStopCapturing(string id);
Then I associate a function with the event SM_IMAGE_PROC like this:
SMStartCapturing(ID, new SM_IMAGE_PROC(image2), new SM_STATE_PROC(state), 0);
- The last thing is: I'm using this structure:
Main Class -> ClassManager
-> ChildClass
When I create the childClass, I pass to it the ClassManager instance, so then it can use some methods that I need from there.
What I'm thinking of is that somehow the position of ClassManager changes and ChildClass tries to get the old reference.
Any Idea?
or Any Idea of where else Can I look for an answer?
|
|
|
|