|
Why don't you just read it into an XmlDocument or an XmlTextReader , which will verify that it's well-formed. Using Internet Explorer - which actually uses MSXML - is totally unnecessary and very inefficient. Once you've got it into an XmlDocument , you can perform XSL transformation, XPath queries, or just navigate and modify the DOM. If you use an XmlTextReader , you could just read it in as text.
If you want to validate it against a schema - something Internet Explorer/MSXML doesn't do automatically - you can use an XmlValidatingReader .
Just see the documentation for these classes in the .NET Framework SDK for more information and examples.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanx Heath, the thing is that I want to know how get an output of any program that you launch within the code. say that IE returned an error, can I detect that and show it to the user?
Using those classes is my next task, first I have to use IE for syntax checking..it is a must.
|
|
|
|
|
forgiven4u wrote:
first I have to use IE for syntax checking
That's what I'm getting at - the XML classes in the .NET Framework check for well-formedness and perform schema validation if you want. This will return you were the error is and let you fix it. You're really taking a backward approach to doing something so simple. Remember, IE isn't even the one validating your XML well-formedness (it doesn't do schema validation) - it's MSXML which IE uses.
forgiven4u wrote:
the thing is that I want to know how get an output of any program that you launch within the code.
There is no universal way of doing this. Sometimes you can redirect stdout and stderr, sometimes you can use the Windows APIs to get Window text, and sometimes you must read a DOM. Every application is designed differently.
forgiven4u wrote:
say that IE returned an error, can I detect that and show it to the user?
If you used the XML classes in .NET, you wouldn't have to worry about this because any invalid XML will throw an exception while loading, giving you the information to present to the user so they can fix it. Besides, if IE is visible, it will display the error.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks again Heath, redirecting stdout & stderr is one cool technique I was seeking. I want to execute a program (no IE) and get it's output.
Such attentive people like you makes the world a better place.
|
|
|
|
|
Do you know the answer how to add/remove references for specific configuration?
I have 2 configurations in my project, "Debug" and "Release" (as usual). I also use a NUnit and other tools that help to develop stable applications. In order to use NUnit I have to add reference: "nunit.farmework" to the list of all project references.
My problem that I don't want to add the reference in the "Release" configuration, I don't want to install NUnit or even copy nunit.framework.dll to the client machine.
Do you know a way to "dynamically add/remove reference for a specific configuration?"
Could reflection help?
Thanks in advance
|
|
|
|
|
I don't think this is possible, and a solution I found is to create a separate DLL where I put all the unit tests. This way I ensure that I only ship release code to our customers, and that I can freely add "tool references" such as NUnit, mock libraries, etc.
IMO, Reflection would not help you because there's no way to add attributes ([Test], [ExpectedException], etc) to a class after it has been loaded.
Due to technical difficulties my previous signature, "I see dumb people" will be off until further notice. Too many people were thinking I was talking about them...
|
|
|
|
|
Although an assembly get referenced on the commandline, it doesnt mean it will be named in the assembly manifest.
"All" you need to do is:
#if NUNIT
#endif
to all the NUint referecences.
|
|
|
|
|
I'm trying to automate some web tasks using an AxWebBrowser in a C# application. The browser is working, and I can modify text box text, etc. The thing I can't figure out is how to "click" an anchor. This works:
IHTMLElement link = (IHTMLElement)doc2.links.item(i,0);
if ( link.innerHTML.Equals("Log Out") )
{
IHTMLAnchorElement a = (IHTMLAnchorElement)link;
object flags = 0;
object targetFrame = "";
object postData = "";;
object headers = "";
this.Cursor = Cursors.WaitCursor;
this.wbMint.Navigate(a.href, ref flags, ref targetFrame, ref postData, ref headers);
}
But what if there is onclick scripting in the Anchor? Tried casting it as (IHTMLLinkElement) as well, but don't see any way to "click".
Any ideas?
|
|
|
|
|
Call link.click() (IHTMLElement::click method). Remember, every element can be clicked, so logically such a method would be defined on the IHTMLElement or its versioned derivatives.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Perfect. I was trying too specific. It strikes me as odd that the more generic IHTMLElement defines click() but IHTMLLinkElement does not have a definition! Ahh well, thanks for the help!
|
|
|
|
|
It doesn't need it since IHTMLLinkElement inherits from IHTMLElement , so the click method is inheritted, too.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Not to belabor the point, but that's what struck me as strange. It's not there. It won't compile ->
D:\My Documents\...(588): 'mshtml.IHTMLLinkElement' does not contain a definition for 'click', which is what led me on this chase in the first place.
Thanks again.
|
|
|
|
|
click is not a member of the IHTMLLinkElement interface, and the interop interface (the RCW) does not inherit like it does in COM, which works a little differently than in languages like C# (the .NET Framework in general, actually).
Technically, it's not the interface that is inheritted anyway, but that the coclass for that interface implements the IHTMLElement interface as well, both of which inherit from IDispatch (sorry, I should have been more technical).
When you do this in scripting, methods of IDispatch are actually used to find and invoke the member, like click . Typically in cases like this, however, the interfaces do actually inherit from their parent or earlier interfaces. It all pretty much results in the same behavior, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am working on a project that requires me to create a database manager (add, delete, edit) for a txt database file (the dbase format is called bibtex, but i can edit the actual text file in almost any way). I wanted to know if anyone had a good idea on how to get that done in C#. I have C++ code that reads the txt dbase into a structure, and I wanted to know if I could use that in C#. Otherwise is there some easy way to read a txt file and store it in a structure.
Thanks.
K
|
|
|
|
|
If you have an OLE DB provider installed for the dbase format - and IIRC it's installed with MDAC - you can simply use ADO.NET which gives you the most flexibility. Just see the System.Data.OleDb namespace in the .NET Framework SDK documentation, as well as the myriad of examples here on CodeProject about using ADO.NET: http://www.codeproject.com/cs/database/[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Are classes always passed by reference to a method? I am getting the same results with and with out the ref keyword with a class. But when i use a int I get ref/value using them in the respective way. Is there anyway to pass a class by value?
thanks
-hammackj
|
|
|
|
|
There's reference types and value types in .NET. Structs, enums, numeric types, booleans and chars are all value types. Everything else is a reference type. Like their names, reference types are always passed by ref while value types are passed by value, though you can - as you've found - use the ref and out (no initialization required) keywords to pass them by ref.
When you get into P/Invocation, keep this in mind. A pointer to an interface or class should not use the ref or out keywords, while a pointer to a struct or a numeric parameter should.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks a ton sir. Clears up everything.
|
|
|
|
|
Actually classes are also passed by value. You're passing a value of a reference.
If you call methodA(A a) and in the methodA you say: a = new A(...), the value of the a will not be changed in the caller scope. But if your method signature is: methodA(ref A a) and then in method you say a = new A(...) then in your caller scope value of a will change.
|
|
|
|
|
Variables are passed by value. The class is still passed a reference. Performing any operation on that instance still occurs on the same instance, while it wouldn't on a value type. You're right about the variable, however. There is a difference, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hallo, I have a strange problem:
When I use DrawString in a drawitem event the text ignores font and brush.
I have a listbox, the unselected items catch the font and brush, but the selected item doesn't. It is printed as unselected.
Do you have any answer??
Bye
|
|
|
|
|
The DrawItemEventArgs contains the properties you need to draw the items, but you must use its State property to determine the state of items, like whether or not it is selected. Keep in mind that since the DrawItemEventArgs.State property uses a flag enumeration, you must use bitwise operators to determine state. For instance, to find out if the item is selected, use something like the following:
bool selected = (e.State & DrawItemState.Selected) != 0;
if (selected)
{
}
else
{
} See Resizable ListBox[^] for a pretty good example (there's many others, too - I just still had that URL in my clipboard used for another reply just a minute ago).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am trying to do a word wrapping in the items of the ListBox.
But I donot see any such property provided by ListBox.
Any idea how can I do this.
Any help would be appreciated.
Thanks,
Binal
|
|
|
|
|
You have to owner-draw the items, and there are a couple articles here on CodeProject that explain how. See An editable multi-line listbox for .NET[^] or Resizable ListBox[^] for a couple decent examples.
Basically, you just owner-draw the ListBox using a multi-line StringFormat and call Graphics.DrawString with that StringFormat . Slightly more is involved, but see the articles for details.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i try to much to deal with the video in the C#
i try to use DShowNet but i don't understand its functions so i need so urgent to know
1- the class or library or dll ..... used to deal with a video in the program
2- i need to cut the video into frames and give each frame its index
3- convert the frames into images
|
|
|
|