Reputation: 11
I've currently huge amount of data (500 mb each) which I'm using lodash and cheerio to parse and fetch parts of it. Problem with new data is that it has some empty tags being incorrectly replaced.
Example:
<apple></apple>
gets replaced by
</apple>
I want to make sure that the previous formatting remains the same. Any regex that I can use to find these new empty tags and replace it with the old correct format?
Upvotes: 0
Views: 90
Reputation: 111696
You probably mean that <apple></apple>
is replaced by <apple/>
(not </apple>
).
<apple></apple>
and <apple/>
are equivalent in XML, and no compliant XML process will treat them differently, so you should not care which is used in your document.
If you truly meant that <apple></apple>
is replaced by </apple>
, then you have a likely irreparably damaged file as you won't know whether any given end tag for apple
should be associated with an empty or nonempty apple
element.
For example, doing a string-level replace of "</apple>"
to <apple></apple>
for
<apple>one</apple>
would result in
<apple>one<apple></apple>
which would not be well-formed.
Upvotes: 2