473,441 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

How to delete string from a XML file opened in a text editor in C#?

Hi,

I have created one XMLEditor and opened XML files in it.

Before closing the file i am validating the xml file and if some invalid entries are present, i am able to fetch the row and column number of the error text in the file.

Now i want delete that error text from the RichTextBox before saving the file.

How to do that in C# .NET?

Thanks,
-Anupam
Nov 13 '07 #1
5 1886
jkmyoung
2,057 Expert 2GB
Could you post how you're retrieving the text from the RichTextBox in the first place?
Can you just use a .Clear method, or try setting the Text property to the empty string?
Nov 13 '07 #2
Could you post how you're retrieving the text from the RichTextBox in the first place?
Can you just use a .Clear method, or try setting the Text property to the empty string?

Thanks a lot for the reply!!

I am validating the saved XML against the XSD at first.

If some invalid text string is found,its the event handler class is getting hit

which i have implemented ..its like....XmlLoaderValidationEventHandler(object sender, ValidationEventArgs e)

but i m not able to retrieve the text(error string) but able to retrieve the row number of the string in text box as i mentioned.

Now with this row number and coln number how will i be able to delete that string from the text box and save the file?

If i know the string anyways i would have set it to selectedString="";

But this is not possible for me as of now..

If its not possible for what i m looking for, atleast can i set the control(cursor) to the start of the error string once event handler is hit so that it will prompt the user to delete the string from XML file manually ??

Suggestion will be much appreciated..

thanks in advance!!

-Anupam
Nov 14 '07 #3
Frinavale
9,735 Expert Mod 8TB
Hi,

I have created one XMLEditor and opened XML files in it.

Before closing the file i am validating the xml file and if some invalid entries are present, i am able to fetch the row and column number of the error text in the file.

Now i want delete that error text from the RichTextBox before saving the file.

How to do that in C# .NET?

Thanks,
-Anupam
From what I understa, you are loading the file into your program to display it into the RichTextBox.

Couldn't you search the text value of this text box for the row that the error exists on (count the number of newlines to get to the row) and then parse that row's text to remove the invalid value?
Nov 14 '07 #4
From what I understa, you are loading the file into your program to display it into the RichTextBox.

Couldn't you search the text value of this text box for the row that the error exists on (count the number of newlines to get to the row) and then parse that row's text to remove the invalid value?

Hi Frinavale,

Thanks for the reply!!

U r absolutely right!! i am indeed loading the file and writing it to the RichTextBox to display it.

but the invalid entry i am talking about, basically can be even a string or single character,number, or a alphaneumaric string.

How will i be able to reach to the row value in the textBox again as my control has come out of it...and reached a diffrent path.

Is there any API by which i can directly call the editor and shift the control there?

Thanks,
-ANupam
Nov 14 '07 #5
Frinavale
9,735 Expert Mod 8TB
Hi Frinavale,

Thanks for the reply!!

U r absolutely right!! i am indeed loading the file and writing it to the RichTextBox to display it.

but the invalid entry i am talking about, basically can be even a string or single character,number, or a alphaneumaric string.

How will i be able to reach to the row value in the textBox again as my control has come out of it...and reached a diffrent path.

Is there any API by which i can directly call the editor and shift the control there?

Thanks,
-ANupam
I've never used RichTextBoxes before (I think they're restricted to Windows and as I'm mostly a web developer I don't want to restrict my user).
I'm unsure of any API that can do this for you.

In order to go to the column value where the error happened, you'll have to count the number of new lines (to get the right line)...then do a SubString on that line starting at the Column value.

From what I remember about XML is that the value has to be within double quotes: ""...so do an extra sub string to extract the exact value...
From there you should probably use your own logic to determine what is invalid about that string.
Nov 14 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: andy | last post by:
I am having an issue with the way SQL server deletes data. I am trying to delete data from the DB and have it completetly gone. Here is what I did 1. added a table with a row of image data...
26
by: S!mb | last post by:
Hi all, I'm currently developping a tool to convert texts files between linux, windows and mac. the end of a line is coded by 2 characters in windows, and only one in unix & mac. So I have to...
1
by: anupam roy | last post by:
Hi, I have created one XMLEditor and opened XML files in it. Before closing the file i am validating the xml file and if some invalid entries are present, i am able to fetch the row and column...
2
by: BAnderton | last post by:
Greetings from beautiful Tucson, Arizona. Question: Is there a way in Python to determine what all file identifiers have been opened by Python, and to close them all? Why I ask: I learned...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.