|
XmlNode root = xmlDocument.DocumentElement;
for (int i = 0; i < root.ChildNodes.Count; i++)
{
XmlNode node = root.ChildNodes[i];
if (node.Name == "NAME")
{
}
}
|
|
|
|
|
add http://www.microsoft.com/GroupPolicy/Settings to a new xml namespace manager and use it with your node select. Something like:
XmlNamespaceManager NSM = new XmlNamespaceManager(YOURXMLDOCOBJINSTANCE.NameTable);
NSM.AddNamespace("some_random_name_like_abcd", "http://www.microsoft.com/GroupPolicy/Settings");
XmlNode whateverNode = YOURXMLDOCOBJINSTANCE.SelectSingleNode("//some_random_name_like_abcd:WhateverElement", NSM);
XPath will generally not work without specifying the namespace, when a namespace is defined.
|
|
|
|
|
thanks, i just tried this and making some progress now
here is what i have to get the text of the whole node and the first child
XmlDocument xml = new XmlDocument();
xml.Load(str);
XmlNamespaceManager NSM = new XmlNamespaceManager(xml.NameTable);
NSM.AddNamespace("abcd", "http://www.microsoft.com/GroupPolicy/Settings");
XmlNode xmln = xml.SelectSingleNode("//abcd:Identifier", NSM);
if (xmln.HasChildNodes == true)
{
if (xmln.FirstChild.Name == "Identifier")
{
this.textBox2.Text = xmln.FirstChild.InnerText.ToString();
}
}
this.textBox1.Text = xmln.InnerText.ToString();
is there a better way to do this or should i get coding?
and thanks to everyone!!!
modified on Thursday, November 13, 2008 4:15 PM
|
|
|
|
|
rather use /abcd:Identifier/abcd:Identifier to get only the child nodes labeled "Identifier" of the root "Identifier" node. Use the full power of XPath if you went that way ... w3 has a great tutorial on how to use them "productive" ... http://www.w3schools.com/XPath/xpath_syntax.asp[^]
Code? Yeah i love it fried together with a glass of wine.
|
|
|
|
|
thanks for the link it has been helpful, I have another question
here is the xml i am trying to query
<GPO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.microsoft.com/GroupPolicy/Settings">
...
<User>
<ExtensionData>
<Extension xmlns:q1="http://www.microsoft.com/GroupPolicy/Settings/FolderRedirection" xsi:type="q1:FolderRedirectionSettings">
.....settings I need to read are child nodes here.....
</Extension>
<Name>Folder Redirection</Name>
</ExtensionData>
<ExtensionData>
<Extension xmlns:q2="http://www.microsoft.com/GroupPolicy/Settings/Registry" xsi:type="q2:RegistrySettings">
.....settings I need to read are child nodes here.....
</Extension>
<Name>Registry</Name>
</ExtensionData>
</User>
</GPO>
Is there a way i can query the xsi:type value?
if not I can query the name but not sure what the best way to jump up to the settings to read them.
this xml file does not always have the same <ExtensionData> entries so i am checking for all possible cases
|
|
|
|
|
i figured out how to do this below is the code i used, could be cleaner if this was the only thing i was checking in the User node
XmlDocument xml = new XmlDocument();
xml.Load(str);
XmlNamespaceManager NSM = new XmlNamespaceManager(xml.NameTable);
NSM.AddNamespace("abcd", "http://www.microsoft.com/GroupPolicy/Settings");
XmlNode xmln6 = xml.SelectSingleNode("//abcd:User", NSM);
for (int i = 0; i < xmln6.ChildNodes.Count; i++)
{
XmlNode Childnode = xmln6.ChildNodes[i];
if (Childnode.Name == "ExtensionData")
{
string ExtDataTest = Childnode.ChildNodes[0].Attributes[1].Value.ToString();
string test = ExtDataTest.Substring(3, ExtDataTest.Length - 3)
}
}
|
|
|
|
|
i have the following code that is suppose to fill a datagrid. the code works fine when queried in the database but when used in the application no results are return. please help!!!!
this is the code i used....
private void cmdCompare_Click(object sender, EventArgs e)
{
string sqlquery;
sqlquery = "select * from " + Table1 + " where not exists ( select * from " + Table2 + " where " + txt_comkey_tbl1.Text + " = " + txt_comkey_tbl2.Text + ")";
OpenDb();
dbCmd = new OleDbCommand();
dbCmd.Connection = dbConn;
dbCmd.CommandText = sqlquery;
dbCmd.CommandType = CommandType.Text;
dbReader = dbCmd.ExecuteReader();
int intSkip = 0, i = 0;
ds = new DataSet();
dbtable = ds.Tables.Add(sqlquery);
for (i = 0; i < dbReader.FieldCount; i++)
dbtable.Columns.Add(dbReader.GetName(i), dbReader.GetFieldType(i));
int intIdx = 0;
while (dbReader.Read())
{
if (intIdx >= intSkip)
{
DataRow r = dbtable.NewRow();
// Assign DataReader values to DataRow.
for (i = 0; i < dbReader.FieldCount; i++)
r[i] = dbReader[i];
dbtable.Rows.Add(r);
}
intIdx++;
}
dgTblDiff.DataSource = ds.Tables[sqlquery].DefaultView;
dbReader.Close();
}
|
|
|
|
|
Use the data adapter to fill a dataset and not a datareader.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
1. Use parametrized queries instead of string concatenation. Parametrized Queries VS String Concatenation[^]
2. If you are filling DataTable why aren't you using DataAdapter instead of manually looping through datareader?
3. Ensure that the connection is initialized and don't leave it open when you no longer need it.
|
|
|
|
|
Nothing jumps out at me; I just wouldn't bother with the DataSet.
Have you stepped through it in the debugger?
And what's the purpose of the intSkip ?
|
|
|
|
|
Hi,
First of all, is there a way to get list of all Web Sites from IIS?
Secondly, how can I get information such as Port, IP Address, etc., about the Web Sites?
Last, can all of this be done in c#?
Any help on this would be appreciated.
Thanks,
Prateek
|
|
|
|
|
Never Mind.
I was able to find out how to do it.
DirectoryEntry iis = new DirectoryEntry("IIS://" + Environment.MachineName + "/w3svc");
foreach (DirectoryEntry site in iis.Children)
{
if (site.SchemaClassName == "IIsWebServer")
{
String siteName = site.Name;
foreach (String propertyName in site.Properties.PropertyNames)
{
PropertyValueCollection values = site.Properties[propertyName];
foreach (object val in values)
{
Console.WriteLine(propertyName + ": " + val);
}
}
}
}
This will get the list of web sites on IIS and their properties. I don't know if this will work for IIS 7 right now.
|
|
|
|
|
Hi all!,
I have a weird question and some code that isn't quite right. I am creating a personal project where I have an already-existing text file which consists of mainly symbols and standard text as follows:
Sample Text File contents:
<jason="human, being, boy, male, animal" />
<human="instinctive, funny, destructive" />
http://www.my_soon-to-be_homepage.com.au/
<qualities="smart, intelligent, funny" />
This file may contain X number of lines, and what I am trying to do is search for the in-betweens, what I mean by that is I want to be able to search for the keywords (human, being, person, hairy, funny, intelligent etc..) that are inbetween the symbols and then put those found keywords into a string so that i can cut, copy, paste, change them at my own will. Then I need to be able to search for a URL that is within that same text file. And then put that URL into a string so I can cut, copy, paste etc..... into a textBox.
I have some code here that searches but it doesn't work the way i want it to. I'd appreciate any samps, tutorials, advice/ or ANY help i can get from anybody. Thanks for taking the time to read this. I hope it wasn't too confusing..
best regards,
j.t.
j.t.
|
|
|
|
|
If you make your file XML you can use an XML reader to access the attribute values. (The values in quotes)
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Either use the System.XML namespace thus formatting your document to use XML standard formatting, either use the System.Text.RegularExpressions namespace similar to:
System.Net.RegularExpressions reg = new System.Net.RegularExpressions.Regex("<[a-z]+=""([a-z,\s]+)"" \/>");
Use expresso to get the expression that best fits ur needs. The above is just a shallow example.
|
|
|
|
|
Oh, sorry, I forgot to post the code I mentioned in my Question. Thanks for helping me, both of you It's much appreciated:
using System.IO;
using System.Text.RegularExpressions;
private void SearchLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if( File.Exists("C:\\Users\\Jase\\Desktop\\Test.txt"))
{
string FileName = "C:\\Users\\Jase\\Desktop\\Test.txt";
StreamReader SearchText = new StreamReader(FileName);
string ReadAll = SearchText.ReadToEnd();
SearchText.Close();
string regMatch = SearchTextBox.Text;
if (Regex.IsMatch(ReadAll, regMatch))
{
MessageBox.Show("Found\n" + "" + regMatch);
}
else
{
MessageBox.Show("Not found\n");
}
}
else
{
MessageBox.Show("Non-Existant File.");
}
}
The only problem with this code is it requires somebody to enter text into a textbox and then it will search for that text in an existing file. I actually need to just search for anything that is inbetween two quotes ("sample thing").
I tried both of your suggestions and I got a little confused and it didn't work, so I went to MSDN before posting another question here and I left MSDN even more confused. Thanks for your quick replies
j.t.
|
|
|
|
|
IsMatch returns a boolean whether it found or not your regex expression in the input string.
The correct way to use regex would be with this basic regex
Regex reg = New Regex("""(.+?)""", RegexOptions.IgnoreCase | RegexOptions.Multiline);
MatchCollection mtc = reg.Matches("input string");
this will return a MatchCollection which u can loop through to get every match of the pattern in the input string. Use the GetEnumerator method of the above MatchCollection to loop through the matches.
Code? Yeah i love it fried together with a glass of wine.
|
|
|
|
|
My problem: reading bits from a file and manipulate them.
So I have to get the 0's and the 1's from a file in an array or something, adjust them and make a file again with them. Is this possible? You guys could help me with some example code or some useful function names. I would really appreciate that
|
|
|
|
|
load bytes from your file and manipulate them using System.Collection.BitArray, convert again to bytes then save to file.
hope it helps
dhaim
ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro"
in the front line gave a lead, in the middle line build goodwill, in the behind give power support
|
|
|
|
|
yes it helps, but
how can I convert BitArray to byte[] ?
BitArray myBitArray = new BitArray(myBytesArray);
byte[] myNewByte = ... ?
|
|
|
|
|
This should work....haven't really tested it.
String path = "path to your file";
System.IO.StreamReader reader = new System.IO.StreamReader(path);
String data = reader.ReadToEnd();
byte[] buffer = Encoding.ASCII.GetBytes(data);
System.Collections.BitArray bits = new System.Collections.BitArray(buffer);
Hope this helps
|
|
|
|
|
yes it helps, but
how can I convert BitArray to byte[] ?
BitArray myBitArray = new BitArray(myBytesArray);
byte[] myNewByte = ... ?
|
|
|
|
|
Check msdn for BitConverter. That should help.
|
|
|
|
|
Hello! I'm new to C# and .NET. Most of the developement I've done lately is in PL/SQL and/or Perl, so C# is "a bit" of a change for me. I've got an architecture question first which I'm sure will lead to more questions.
I work for a company that has hundreds of remote devices around the country. I need to write an app that, in a nutshell, reads the details of these devices from a database, contacts them via a phone call using a modem pool, downloads a data file, then updates certain fields in the database.
I'd like opinions on whether this is a good way to do it or not:
I'm thinking of writing two separate apps that communicate via remoting. One app (the client) would be the one that 'talks' to the database. It periodically reads the database to see which devices need to be contacted. It would be multi-threaded so it can initiate multiple contacts at once.
The second app (the server) would be responsible for controlling the modem pool (up to 20 modems/phone lines). It would take a request from the client, contact the device, and get the data file, then respond back to the client with the status of the call (sucess or failed and why failed).
Does this sound like a good way to proceed? Any hidden 'gotchas' I should know about? Threading, remoting, dialing a modem, etc, is all new to me so this should be..... 'interesting'.
- Dave -
|
|
|
|
|
I'm getting crazy...
I've tried to run through this.Controls
...but it only found the MenuStrip and ToolStrip. The names of the items like "mnuOptions" weren't listed.
So I've tried stupid like this.components.Components.GetEnumerator()
...and got only one element.
All objects can be accessed by typing this. and the name of object. Even those of the MenuStrip or ToolStrip. But at runtime they can't be accessed by this.Controls["menuItemXY"] .
I know about recursive getting controls. But this solution doesn't get the items of a MenuStrip.
Is there any solution to get really all objects in a form at once and without switching the type of object?
modified on Thursday, November 13, 2008 11:16 AM
|
|
|
|