473,396 Members | 2,158 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,396 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 1885
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.