我的数据设置如下:
|------------------------------------|------------------------------------|
| Old URL | New URL |
|------------------------------------|------------------------------------|
| http://example.com/page-a | http://newsite.com/page-a |
|------------------------------------|------------------------------------|
| http://example.com/page-b | http://newsite.com/page-a |
|------------------------------------|------------------------------------|
| http://example.com/page-c | http://newsite.com/page-b |
|------------------------------------|------------------------------------|
| http://example.com/page-d | http://newsite.com/page-c |
|------------------------------------|------------------------------------|
| http://example.com/page-e | http://newsite.com/page-c |
|------------------------------------|------------------------------------|
| http://example.com/page-f | http://newsite.com/page-c |
|------------------------------------|------------------------------------|
| http://example.com/page-g | http://newsite.com/page-c |
|------------------------------------|------------------------------------|
| http://example.com/page-h | http://newsite.com/page-d |
|------------------------------------|------------------------------------|
| http://example.com/page-i | http://newsite.com/page-d |
|------------------------------------|------------------------------------|
我需要将这些数据转换为XML格式,如下所示:
<urls>
<url>
<old>http://example.com/page-a</old>
<old>http://example.com/page-b</old>
<new>http://newsite.com/page-a</new>
</url>
<url>
<old>http://example.com/page-c</old>
<new>http://newsite.com/page-b</new>
</url>
<url>
<old>http://example.com/page-d</old>
<old>http://example.com/page-e</old>
<old>http://example.com/page-f</old>
<old>http://example.com/page-g</old>
<new>http://newsite.com/page-c</new>
</url>
<url>
<old>http://example.com/page-h</old>
<old>http://example.com/page-i</old>
<new>http://newsite.com/page-d</new>
</url>
</urls>
每个<url></url>
都是一行,基本上是一个新行。如果我只为每个旧URL提供<url>
,那么这不是问题。但是,对于每个<old></old>
,我有<new></new>
个不同的数量。在我的脑海中,我能想到的唯一方法就是拥有多列旧的并将日期从行转换为列,但这似乎需要AGES。我有成千上万的事要做。还有其他人知道更好的方法吗?