|
I am using this code to read one the childs using its attribule but it's always reading the first child though the selected GUID is the last child? what's the problem:
xml_documen.SelectSingleNode("/Resume/Contacts/Contact[@ID='73298407-06fa-462a-be30-254a5318176c']");
txtContactNumber.Text = xml_documen.GetElementsByTagName("Number")[0].InnerText;
|
|
|
|
|
You'll need to clarify a little. The problem is with the first line? how is the second line involved?
I don't see any problem with the first line, unless you have more than one contact node with the same attribute value.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
what ever GUID i use it will just display the first only!!
|
|
|
|
|
this is my XML:
<?xml version="1.0" encoding="utf-8"?><br />
<Resume><br />
<Education /><br />
<Contacts><br />
<Contact ID="c4411c02-4556-4809-861b-60b68f9820de"><br />
<Decsription>Mobile</Decsription><br />
<Number>1111</Number><br />
</Contact><br />
<Contact ID="cea724c3-e81a-494c-bcf6-e9a67e85d2e6"><br />
<Decsription>Residence</Decsription><br />
<Number>22222</Number><br />
</Contact><br />
<Contact ID="73298407-06fa-462a-be30-254a5318176c"><br />
<Decsription>Mobile</Decsription><br />
<Number>7878888</Number><br />
</Contact><br />
</Contacts><br />
<Detail ID="ae61a549-ca27-4f93-9d5a-8b89bebc4bf9"><br />
<Title>RESUME</Title><br />
<Objectives>testtt</Objectives><br />
<Created>2010-03-20T13:59:28.028866+03:00</Created><br />
<Updated>2010-03-20T13:59:28.028866+03:00</Updated><br />
<PersonalInfoTitle>Personal Info</PersonalInfoTitle><br />
<FullName>Yahoo</FullName><br />
<Nationality>CL</Nationality><br />
<DateOfBirth>1973-03-20T00:00:00</DateOfBirth><br />
<DateOfBirthFormat>dd/MM/yyyy</DateOfBirthFormat><br />
<Gender>F</Gender><br />
<MaritalStatus>Married</MaritalStatus><br />
<MailingAddress>mailing adr</MailingAddress><br />
<City>manama</City><br />
<Country>AW</Country><br />
<Email>jrahm@bbbb.com</Email><br />
<Photo>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4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FFc5oFFFFAGHr3+th/wB01kVva6wFtGvcv/SsGt4fCZy3CgdaKB1qxB3oo70UAFWtOuDb3iMOjHac+hqrRSauB2dFVrG5+1WiSfxDhvrVmuZqxqFFFRzSrBC8rdFGaAMLWbgy3flcbY/5ms2nyyGWVnbqxzTK6UrKxkwoHWigdaYB3oo70UAFFFOjRpZFRRlmOBQBv6IuLEn1c1pU2ONYkCIAAPSnVzN3dzRBVXUl3afMP9nNWqCAQQRkHqKFoxnGUVYvofIvJE24XOVx0xVeuhGQUDrRQOtMAPWpIoZZm2xIzH2FbNroqJ81wd7f3R0rUSNI0CooVR2ArN1F0KUTFt9Dc8zuFH91eTWtBaQWy4ijAPr3P41NRWbk2UkkFFFFSMKKKKAI5oIp12yxq49+1ZVxoeSWt5Mf7L/41s0U1JrYTSZyU9rNbnEsZX37VCOtdkQGBBAIPY1n3OjwTfNF+6f26flWqqdyXE0aKKKxLCiiigAooooAKKKKACiiigAooooA/9k=</Photo><br />
<ContactsTitle>Contacts</ContactsTitle><br />
</Detail><br />
</Resume>
|
|
|
|
|
Reformat this appropriately so it fits on the screen.
You also did not answer my question
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
no.. every one has a different GUID as shown in my xml
|
|
|
|
|
You still DID NOT answer the question. What does the second line have to do with it? The first line works fine and returns the correct node.
You also did not correct the xml post.
If you want assistance, please read, follow the directions, and answer the questions.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
i am sorry.. i didn't read the question
Actually I need to read a specific node by referring to it's attribute// that's why in this example:
xml_documen.SelectSingleNode("/Resume/Contacts/Contact[@ID='73298407-06fa-462a-be30-254a5318176c']");
I am trying to read that specific node but it's giving the result of the first node
|
|
|
|
|
I've tried your example and it returns the the 3rd contact node as expected.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
jrahma wrote: txtContactNumber.Text = xml_documen.GetElementsByTagName("Number")[0].InnerText;
This line will always return the first node.
I think what you are after is;
XmlNode selectedNode = xml_documen.SelectSingleNode("/Resume/Contacts/Contact[@ID='73298407-06fa-462a-be30-254a5318176c']");
txtContactNumber.Text = selectedNode.SelectSingleNode("Number").InnerText;
|
|
|
|
|
I have some function, which makes HttpWebRequest and returns response (string).
Everything works fine except cases when it gets 502 status - Bad Gateway.
In this case try-catch block:
try
{
m_Rresponse = (HttpWebResponse)m_HttpWebRequest.GetResponse();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
if (m_Rresponse.StatusCode == HttpStatusCode.BadGateway || m_Rresponse.StatusCode == HttpStatusCode.GatewayTimeout ||
m_Rresponse.StatusCode == HttpStatusCode.InternalServerError || m_Rresponse.StatusCode == HttpStatusCode.ServiceUnavailable)
{
Console.WriteLine("Sleeping 10 seconds...");
Thread.Sleep(10000);
}
}
The question is why In case of BadGatway "Sleeping 10 seconds..." never printed?
Thanks
|
|
|
|
|
Since I don't have any way of generating a 502 error, I have to assume that is does not set m_Rresponse when it throws an exception - which makes sense, since the throw instruction will terminate processing and transfer control to the catch block immediately. The documentation[^] says "If a WebException is thrown, use the Response and Status properties of the exception to determine the response from the server." which makes more sense to me than relying on an exception completing the instruction that detected the problem.
I am surprised it works for any error, not just 502!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
OriginalGriff wrote: I am surprised it works for any error
That makes a lot of sense.
|
|
|
|
|
what the meaning of this code?
class MouseInvoker
{
#region Declaration
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
#endregion
#region Move Cursor
public static void move(int X, int Y)
{
Cursor.Position = new Point(X, Y);
}
#endregion
#region Left Click
public static void leftClick(int X, int Y, int count)
{
for (int c = 0; c < count; c++)
{
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
System.Threading.Thread.Sleep(100);
}
}
#endregion
#region Right Click
public static void rightClick(int X, int Y, int count)
{
for (int c = 0; c < count; c++)
{
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, X, Y, 0, 0);
System.Threading.Thread.Sleep(100);
}
}
#endregion
}
|
|
|
|
|
|
there some error when i klik mouse in pc client, the error on this code
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
|
|
|
|
|
It means you should read this[^] before posting anything else.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hello,
I created an object "polzisce" from a class called Matrika(this is class that creates two dimensional array) and it's constructor takes two parameters.
Those two parameters are actualy X an Y axis and they are not fixed size.
public class Matrika
{
//constructor
public Matrika(int x, int y)
{
int[,] matrika = new int[x, y];
}
}
static void Main(string[] args)
{
Matrika polzisce = new Matrika(5, 5);
}
The question is:
Is object "polzisce" actualy two dimensional array after it is created?
How can i get that two-dimensional array "matrika" from constructor?
Thanks! Alen.
|
|
|
|
|
av7254 wrote: Is object "polzisce" actualy two dimensional array after it is created?
No, it HAS_A two-dimensional array.
av7254 wrote: How can i get that two-dimensional array "matrika" from constructor?
If that's what you want, then why create Matrika at all?
On the other hand, you could write a converter for it.
But why not simply write a static method that takes the two parameters and creates the array?
|
|
|
|
|
your way is simplier but, i want to do it like this.
all i want is to get the x and y value from constructor.
Use cases:
Matrika polzisce = new Matrika(10,20);
Matrika polzisce = new Matrika(5,2);
maybe:
Matrika polzisce = new Matrika(1000,1000);
in this case: Matrika polzisce = new Matrika(5,5);
Constructor runes first when object is created and contains varibles x=5 and y=5(actualy limits of array). I need those two to create two-dimensional array.
I don't know how to access those varibles in the constructor, that i can create 2d array and that object "polzisce" will contain 2d array 5x5
Tnx for all other posts!
I appreciate!
|
|
|
|
|
Not exactly a difficult thing to do: it is pretty common:
Using your original code:
public class Matrika
{
public int[,] arrayOfInts;
public Matrika(int x, int y)
{
arrayOfInts = new int[x, y];
}
}
static void Main(string[] args)
{
Matrika polzisce = new Matrika(5, 5);
for (int x = 0; x < 5; x++)
{
for (int y = 0; y < 5; y++)
{
Console.WriteLine(polzisce.arrayOfInts[x, y]);
}
}
} Note that it is not considered good practice to declare the array as public: I did this only to simplify this example.
Note also that the ints are not initialised, so they will all be zero.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Thanks!
i have solved this thing it is realy preety simple
<br />
public class Matrika<br />
{<br />
public int mat_x;<br />
public int mat_y;<br />
public Array matrika;<br />
<br />
public Matrika(int x, int y)<br />
{<br />
mat_x = x;<br />
mat_y = y;<br />
matrika = Array.CreateInstance(typeof(int), x, y);<br />
{<br />
But, why did you say that public atributes are no ok?
|
|
|
|
|
av7254 wrote: why did you say that public atributes are no ok
This may take a little while to explain:
Assume you have a class: MyClass which contains a string and an int.
public class MyClass
{
public string UserName;
public int UserID;
....
}
You write your class, you test it, you are happy it works.
So happy, you use it to handle all the user identity work in your entire app!
Then the boss comes along, and says he wants the user name to be in two parts in the database: First name, and second name. Oh, and the userID is not an int, it's going to be a GUID.
How many classes do you have to change to implement this? How much code to you have to change, and test, and document?
If instead you had written the class as:
public class MyClass
{
private string userName;
public string UserName
{
get { return userName; }
set { userName = value; }
}
private int userID;
public int UserID
{
get { return userID; }
set { userID = value; }
}
}
When your dumb boss comes along with his changes, how much rework is there to do? Only the one class, because you can change the internals of MyClass without affecting the outside world:
public class MyClass
{
private string firstName;
private string lastName;
public string UserName
{
get { return firstName + " " + lastName; }
set
{
string[] names = value.Split(' ');
if (names.Length != 2)
{
throw new ApplicationException("Name must have first and last components");
}
firstName = names[0];
lastName = names[1];
}
}
private GUID userID;
public int UserID
{
get { return userID.GetHash(); }
set { userID = GetGUID(value); }
}
}
This is one of the cornerstones of OOP - encapsulation. Never expose your internals more than you have to!
When you are starting off, it seems like a lot of fussing about over nothing! But it very quickly becomes second nature, and does give real benefits - almost from day one. If nothing else, it forces you to think about how your class will be used, and what you want to expose to the outside world. Very often, this affects the internal design in a good way, by the realization that a small change in the original plan can give a more flexible class with wider applications. This leads to more code re-use, and thus better reliability.
I hope that made some sense!
[edit]userID changed to GUID in last example - forgot that when I cut and pasted[/edit]
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Maybe you should google encapsulation, since I think that is what your trying to do.
|
|
|
|
|
polzisce isn't two dimensional array..
matrika is two dimesional, and if you want to access it make it member of class and write a method..
|
|
|
|