문제

I have a very large string that I am trying to convert from an old standard to marc21 xml standard.

The following line of code:

temp1 = inputString.Replace("<marc:controlfield tag=\"LDR\">", "<marc:leader>");

Produces the following:

<marc:leader>^^^^^nam^a22^^^^^3a^4500</marc:controlfield>

The problem is quite evident.

I perform a blanket conversion on a particular term and replace it with 'marc:controlfield'. Towards the end of my conversion process, I start to handle the leader element. Which is where I am right now. The xml savvy of out there know that:

</marc:controlfield>

needs to be:

</marc:leader>

Once this is done, my string can be tested for well formedness and validity and etc. I am struggling on how to grab the closing brackets for a leader element and replace it with xml as shown above.

Originally the Leader element looks like:

<fixfield id="LDR">^^^^^nam^a22^^^^^3a^4500</fixfield>

Any help is greatly appreciated.

도움이 되었습니까?

해결책

use Regex:

strResult = Regex.Replace(inputString,
                          "<marc:controlfield tag=\"LDR\">([^<]*)</marc:controlfield>",
                          "<marc:leader>$1</marc:leader>");  

explain:

[^<]*  

means any character except: '<' 
(0 or more times, matching the most amount possible)  

다른 팁

maybe i'm just not understanding you correctly, but why wouldn't running

temp1 = temp1 .Replace("</marc:controlfield>", "</marc:leader>");

after your first conversion work for you?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top