|
I need to remove all comments ( between tags) from XML string.
I tried the following code but comments are still present.
How to remove comments ?
string RemoveComments(string sDoc) {
XmlDocument xDoc = new XmlDocument();
xDoc.PreserveWhitespace = false;
xDoc.LoadXml(sDoc);
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
xtw.IndentChar = ' ';
xtw.Indentation = 2;
xtw.Formatting = Formatting.Indented;
xDoc.WriteContentTo(xtw);
xtw.Close();
sw.Close();
return sw.ToString();
}
Andrus
|
|
|
|
|
Pseudo code but it should give you an idea
XPathNavigator nav = xDoc.CreateNavigator();
while(nav.MoveToNext(XPathNodeType.Comment))
{
}
only two letters away from being an asset
|
|
|
|
|
Thank you.
I tried the folowing code but comments are still present.
What I'm doing wrong.
string RemoveComments(string sDoc) {
XmlDocument xDoc = new XmlDocument();
xDoc.PreserveWhitespace = false;
xDoc.LoadXml(sDoc);
XPathNavigator nav = xDoc.CreateNavigator();
while (nav.MoveToNext(XPathNodeType.Comment)) {
nav.DeleteSelf();
}
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
xtw.IndentChar = ' ';
xtw.Indentation = 2;
xtw.Formatting = Formatting.Indented;
xDoc.WriteContentTo(xtw);
xtw.Close();
sw.Close();
return sw.ToString();
}
Andrus
|
|
|
|
|
How about opening the xml file with a StreamReader, read all the text inside and remove all the "" substrings?
|
|
|
|
|
Thank you.
Can you give example how to implement this ?
I'm bit new to C#
Andrus
|
|
|
|
|
Try this:
StreamReader sr = new StreamReader("myOldFile.xml");<br />
StreamWriter sw = new StreamWriter("myNewFile.xml");<br />
<br />
string theText = sr.ReadToEnd();<br />
sr.Close();<br />
<br />
theText = theText.Replace("<!--", "");<br />
theText = theText.Replace("-->", "");<br />
<br />
sw.Write(theText);<br />
sw.Close();
Have a nice day!
|
|
|
|
|
Thank you.
I'm sorry maybe my question was incorrect.
I need to remove comment tags including their contents.
Result must be valid XML.
Your code removes only comment tags.
Result is not valid XML.
How to remove comment tags contents also ?
Is it possible to use some strign function which removes also all characters between comment tags ?
Andrus
|
|
|
|
|
Thank you.
I'm sorry maybe my question was incorrect.
I need to remove comment tags including their contents.
Result must be valid XML.
Your code removes only comment tags.
Result is not valid XML.
How to remove comment tags contents also ?
Is it possible to use some string function which removes also all characters between comment tags ?
Andrus
|
|
|
|
|
I have a large datagrid which I can filter by changing the query and reloading the datagrid but this takes time as its a large amount of data. Is there a way to filter a datagrid without having to reload the data?
|
|
|
|
|
Use a DataView and filter that. So your code would be something like this, assuming you have a single table returned from your dataset.
DataView dv = dataSet.Tables[0].DefaultView;
dv.RowFilter = "ColumnName = 'value'";
dataGrid.DataSource = dv;
dataGrid.DataBind();
At least that should be pretty close to some code that would work.
Hope that helps.
Ben
|
|
|
|
|
Thanks worked like a charm.
|
|
|
|
|
Hi All,
I have deployed my project and people are having trouble because the link for the InstallUrl is one that redirects you.
http://go.microsoft.com/fwlink/?LinkId=9832
Under the launch conditions in the Microsoft .NET Framework it has a red exclimation point on it. How do I fix this? I programmed in Visual Studio 2005. Should I Allow Later Versions?
|
|
|
|
|
Hey all,
Could anyone help me in testing a stored procedure for a report? what could be the outcomes for that?
|
|
|
|
|
To test a stored procedure ensure you have a known set of inputs. That includes the contents of the tables as well as the parameters. Run the stored procedure and ensure the output is as you expect. There isn't a lot more to it than that. The difficulty is ensuring a consistent input set so you are not tracking down false failures in the stored procedure when the test data is at fault.
|
|
|
|
|
HI all,
i am developing a windows applicaiton,
here in between two controls i need to generate a Horizantal Line,
i couldn't get this, can u please suggest me to how to Draw a line Programatically
thnx in advance,
prashanth
prashanth,
|
|
|
|
|
form have an event which name is Paint.
in this event u can use :
e.Graphics.DrawLine(--,--,--)
|
|
|
|
|
Hello. I have a problem and I hope you can help me.
I have the two classes below.
public class MyObject
{
int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
public class MyClass
{
MyObject _object;
public MyObject Object
{
get { return _object; }
set { _object = value; }
}
}
In my program I do that:
MyClass m = new MyClass();
private void Form1_Load(object sender, EventArgs e)
{
bindingSource1.DataSource = m;
}
and I create a comboBox and set his DataBinding to the "bindingSource1 - Object".
I populated the comboBox with Items.
My questions are: How can I populate the ComboBox with the Object, and when I select a Item from comboBox, that is a Name, he must give to me the Id for that Name.
10x
|
|
|
|
|
I have an application where the user(s) must only be able to open one copy of the application. I created a Mutex object that is created on startup to limit the number of possible copies on the computer that normally runs to software to just one, but it is possible at present for the customer to install this software on multiple machines. If someone opens a copy of this software on one machine while a user on another computer is running the software, that could create problems. Is there a way to check whether a process is running on another machine on the customer's network and, if so, to shut down the copy of the application the user tried to start up? Thanks.
|
|
|
|
|
This may seem like a difficult problem to solve, but what you need is a piece of server software that keeps track of the number of instances currently running. Then in your client software (the actual application being run), you need to have it first connect to the server software and find out how many instances are currently running. If greater than zero, display a message to the user, otherwise allow the program to continue.
Hope this helps.
Phil
|
|
|
|
|
Hi all,
i am making a windows based application, here i am using a DataGridView(of C#2.0)
here i wanna add a label control in my GridView,
i have to fill a colomn say(LabeledData) with a Label Control For each row,
hope u got me.
please help me solving this problem
bye byes,
thnx in advance
prashanth
prashanth
|
|
|
|
|
Hi,
In visual 2005 I Created a new MDI project and by defualt it has a nice GUI with menus and toolbars. In addition, I have create a child form and can successfully load within the MDI parent form. Now, I would like to change the top menus i.e File,Edit,Help sorting order whenever a childform is opened that has it's own menu.
For instance by default:
File Edit View Help
When a childform is opened I want to display its menu like
File Edit GridView View Help
Thanks
|
|
|
|
|
Never done it myself but I think this should be possible using the MergeOrder and MergeType properties of MenuItem class or MergeAction and MergeIndex properties of ToolStripMenuItem class, respectively.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I'm calling another C# service from a http request handler and I need to add a persistant cookie to the service request.
I've tried from within the procedure that initiates the service call:
HttpCookie mycookie = new HttpCookie("myCookie");
httpContext hc = HttpContext.Current;
myCookie.Value = File.ReadAllText("c:\\temp\cookie.txt");
hc.Request.Cookies.Add(myCookie)
<call the="" service="">
What I get is the HttpContext is Null and I can't add anything to it. I'm obviously going about this the wrong way, can someone give me a shove in the right direction?
Thanks in advance!
|
|
|
|
|
Hi,
I want an client Server Application.Where reliability is main issue.
In my application, there will be huge and frequent data to be transfered.
Which one shall i use.
Eswar
|
|
|
|
|
SakthiSurya wrote: Which one shall i use.
The first one.
Seriously, your question is too broad and general to get a meaningful answer. You're more likely to get a meaningful answer if you post specific questions, e.g. "For a client/server architecture where both are .NET apps, should I use .NET remoting or WCF?"
|
|
|
|