|
Hi,
I'm looking for an example of how to read xmls and count the number of times a specific element appears in it. I haven't had much luck, but have been looking for the past 3 hours for examples on the web as to how to do this. I'm a little confused as to the .SelectSingleNode syntax as well. If anyone has a class or method that I can point to an xml, search for a string and output the results, I'll be able to play with it and tweak it and teach myself how this works.
Thanks!
|
|
|
|
|
Is the element always at the same level? You are looking for multiple nodes so SelectSingleNode isn't what you want. You probably want SelectNodes and then get the Count of the returned XmlNodeList. Without knowing your schema I can't give you the exact XPath to use. I do not recommend a flat string search.
|
|
|
|
|
I believe they are on the same level
There is a root element, and the element I am searching for is always at the next level right under the root level element. I could do a string search, as the element is unique with the <>, but if that is a poor way of doing it, I would rather do it the right way.
|
|
|
|
|
Why are you using SelectSingleNode? Why aren't you using SelectNodes to retrieve all the matching nodes? Why not use XLinq?
|
|
|
|
|
Hi,
I tried this and it didn't work? I wasn't sure where to initialize the xml doc name though?
XmlDocument xmlDoc = new XmlDocument();
documentElements = xmlDoc.SelectNodes("Document").Count;
Console.WriteLine(documentElements);
Console.ReadLine();
|
|
|
|
|
First things first, I'd use /Document to iterate over the child nodes of the root element looking for Document. If the node name has a namespace, you'll need to reference that namespace in there.
|
|
|
|
|
Hi,
If this is what you meant, it comes back with a value of 0
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"c:\temp\testzip\test.xml");
documentElements = xmlDoc.SelectNodes("t").Count;
Console.WriteLine(documentElements);
Console.ReadLine();
I even set the string to just "t" and that still returns a 0? So I must be doing something wrong.
|
|
|
|
|
Unless you have an XML element called t that is exactly what should happen. SelectNodes takes an XPath expression as an argument. It isn't a string search. If you are looking for Document elements you need to search for /Document. The / tells it to search from the document root. Otherwise it will search from whatever point you are at in the file at the time.
If you are going to use XML as your data format you should really make an effort to learn XPath. XPath tutorial[^]
|
|
|
|
|
Hi,
Thanks for the link
It looks like I have to have
documentElements = xmlDoc.SelectNodes("//Document").Count;
to get it to work, so it starts at the root only if there are 2 slashes? I got that from the link you sent me so thanks
|
|
|
|
|
hello every one!
when i use this
SendKeys.Send("{PRTSC}");
it only capture the form or small image of it
what is the problem?!
EASY COME EASY GO
|
|
|
|
|
|
thanks but i have some programs that i made it did not capture so what do you suggest?
EASY COME EASY GO
|
|
|
|
|
sanforjackass wrote: thanks but i have some programs that i made it did not capture so what do you suggest?
How did you try capturing the screen in those programs? The same method as described in your original post?
Anyway, if you haven't read the article I recommended, I suggest you do that - I'm almost sure it will help you.
|
|
|
|
|
OK i will let you try it
but first i should send you my program run it then try to capture with your program.
does it work?
(what is your email)
EASY COME EASY GO
|
|
|
|
|
Seriously you don't expect him to sit down en debug your program? Suggesting that is quite rude if you ask me.
Do this the right way: provide the code snippet that doesn't work and let people here have a look at it.
|
|
|
|
|
dont be a smart
if you think you can solve it send me your email then i send you my program then try it,
it works good the problem is when i use the other program to get image of the desktop it does not show my program. why
EASY COME EASY GO
|
|
|
|
|
I don't want you to send me your program and really doubt anyone else in here want that either. You can't expect people to do that kind of work for you - and I still believe asking for it is rude and should be avoided. My guess is people will be less interested in helping you if you use that approach.
|
|
|
|
|
ok if you dont want to!
i will try to explain my program
the first program:
it only show the status of the battery in transparency form it is looks like only the text show
the second program:
just i said before:
SendKeys.Send({"prtsc"})
this.backgroundimage=clipebored.getimage();
it only show a small part of the desk top or only the form
when i use your programs it works but my first program does not show in it.
what is the problem?!!!!!!!!!!
EASY COME EASY GO
|
|
|
|
|
hello may i know how do i go abt getting darkest pixel from a image and apply a floodfill?
|
|
|
|
|
You'll pretty much have to iterate through each pixel and then keep the darkest one you find. You will also have to define "darkest" if the image isn't greyscale.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Bitmap objBitmap = new Bitmap(pictureBox3.Image);
for (int y = 0; y < objBitmap.Height; y++)
{
for (int x = 0; x < objBitmap.Width; x++)
{
}
}
do i do this way? if my image is greyscale how do i go about doing it? sorry i am very new to programming.
|
|
|
|
|
If I were you, I'd look at using a third party library such as AForge for this. If you must do this, then you are going to have to write unsafe code to efficiently manipulate the pixels. I'd start off by reading Christian Graus' articles here on CP on image processing.
|
|
|
|
|
The important thing is the pixel format. If you can use GetPixel on the image (so pixel format is not indexed) and you want to avoid the usual headaches of locking bits, you can use GetBrightness method for each one. If pixel format is indexed you will not be able to use GetPixel, so you will have to lock bits and get the color of each pixel from the palette before you can use GetBrightness. This little sample[^] might help you in the last case.
|
|
|
|
|
Hi,
In my webbrowser application frequently iam getting Internet Explorer Script Error.....the page not support the Jscript. I created the webbrowser application using IE Component. How to rid of this...kindly give me one solution.
krishna
|
|
|
|
|
Hello Krishna!
Sounds like a JavaScript issue so please post this question in the correct forum: "JavaScript".
It's there. I know, I've been there before .
Plus to make it easier for us to help you:
1. Reproduce the exact error message. A screeshot would be nice.
2. Give a small concise example that will enable us to reproduce that error.
Tanks,
Manfred
|
|
|
|