What's the most efficient way to replace characters in an XML document before
it is loaded into a parser? Chars I'd want to replace are in attributes and
there can be N attributes, also let's assume that I'm not familiar w/ the
structure of the XML so that I'll have to read/replace/load via stream.
Is this possible
OpenStream->Replace char(s)->To XML parser ? If so then how?
Art 3 1430
Art <Ar*@discussions.microsoft.com> wrote: What's the most efficient way to replace characters in an XML document before it is loaded into a parser? Chars I'd want to replace are in attributes and there can be N attributes, also let's assume that I'm not familiar w/ the structure of the XML so that I'll have to read/replace/load via stream. Is this possible OpenStream->Replace char(s)->To XML parser ? If so then how?
You could write your own TextReader which read from another text reader
and made any replacements. If you only want to replace characters which
are in attributes, however, that makes it a good deal harder. I would
suggest loading it into a DOM tree, then going through each node and
replacing the attributes in each node.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jon
What if you are not familirar w/ the XML structure? What if documents are
sent to you using different schema. I mean - it would probably be possible to
code generic solution, which (starting at the root node) recursively asks
for children and attributes and then changes them when unwanted character
occurs but that would probably be an overkill.
Reading XML as a stream you dont' have to worry about what's a node, element
or an attribute. You'd just take what's at at cursor's position and replace
as necessary.
But then how do you load examined stream into DOM?
Thanks for your help!
Art
"Jon Skeet [C# MVP]" wrote: Art <Ar*@discussions.microsoft.com> wrote: What's the most efficient way to replace characters in an XML document before it is loaded into a parser? Chars I'd want to replace are in attributes and there can be N attributes, also let's assume that I'm not familiar w/ the structure of the XML so that I'll have to read/replace/load via stream. Is this possible OpenStream->Replace char(s)->To XML parser ? If so then how?
You could write your own TextReader which read from another text reader and made any replacements. If you only want to replace characters which are in attributes, however, that makes it a good deal harder. I would suggest loading it into a DOM tree, then going through each node and replacing the attributes in each node.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Art <Ar*@discussions.microsoft.com> wrote: What if you are not familirar w/ the XML structure? What if documents are sent to you using different schema. I mean - it would probably be possible to code generic solution, which (starting at the root node) recursively asks for children and attributes and then changes them when unwanted character occurs but that would probably be an overkill. Reading XML as a stream you dont' have to worry about what's a node, element or an attribute. You'd just take what's at at cursor's position and replace as necessary.
I'm not entirely sure what you mean by "reading XML as a stream". If
you *only* want to do a replacement within attributes, you *do* need to
know where you are.
But then how do you load examined stream into DOM?
What I was proposing was a class derived from TextReader which took
another TextReader, and when it was asked for some characters, read
some from the original and made any replacements. You could use that to
build the DOM in the normal way.
However, if you're going to load it into a DOM anyway, why not just
perform the replacement on the in-memory version after it's loaded?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bill Burwell |
last post by:
I am converting a VB6 WebClass application to VB.Net. Used the VB upgrade
tool to do the conversion - and it left me a lot of little code things to
do. Did those code things and got my app to...
|
by: Eric Lilja |
last post by:
Hello, I had what I thought was normal text-file and I needed to locate a
string matching a certain pattern in that file and, if found, replace that
string. I thought this would be simple but I had...
|
by: hagai26 |
last post by:
I am looking for the best and efficient way to replace the first word
in a str, like this:
"aa to become" -> "/aa/ to become"
I know I can use spilt and than join them
but I can also use regular...
|
by: Johnny Google |
last post by:
Here is an example of the type of data from a file I will have:
Apple,4322,3435,4653,6543,4652
Banana,6934,5423,6753,6531
Carrot,3454,4534,3434,1111,9120,5453
Cheese,4411,5522,6622,6641
The...
|
by: Michele Petrazzo |
last post by:
Hi,
a lot of times I need to replace more than one char into a string, so I
have to do something like
value = "test"
chars = "e"
for c in chars:
value = value.replace(c, "")
A solution...
|
by: gs |
last post by:
let say I have to deal with various date format and I am give format string
from one of the following
dd/mm/yyyy
mm/dd/yyyy
dd/mmm/yyyy
mmm/dd/yyyy
dd/mm/yy
mm/dd/yy
dd/mmm/yy
mmm/dd/yy
|
by: |
last post by:
dim br as BinaryReader(stream)
dim buf(5000) as byte
br.Read(buf,0,5000)
closeit..
I have read a binary file into a buffer. This buffer contains many different
chars as well as a few null chars....
|
by: sherihan2007 |
last post by:
Hi
while am running perl script which parses an XML file in AIX following error is getting:(i have given use XML::parser in the script)
Can't load...
|
by: Hongyu |
last post by:
Hi,
I have a datetime char string returned from ctime_r, and it is in the
format like ""Wed Jun 30 21:49:08 1993\n\0", which has 26 chars
including the last terminate char '\0', and i would...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
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...
|
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,...
|
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...
| |