XML 요소 재정의

CSharpBeginner

C #을 사용하고 있습니다.

동일한 execpt 특정 요소 값으로 보이는 2 개의 xml 파일이 있습니다.

원본 파일 :

<tasks>
  <task id="1" >
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
      <CipherData>
        <CipherValue>+bv8xdFfDzXai3rB1D+c2voJ/mRkuQHJfV34iWB2wyezR3wxG5UnLmznq4i2emIh4Z+8KukZEKJmM8=</CipherValue>
      </CipherData>
    </EncryptedData>
    <AnotherElements/>
  </task>
  <task id="2" >
   <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
      <CipherData>
        <CipherValue>+bv8xdFfDzXai3rB1D+c2voJ/mRkuQHJfV34iWB2wyezR3wxG5UnLmznq4i2emIh4Z+8KukZEKJmM8=</CipherValue>
      </CipherData>
    </EncryptedData>
    <AnotherElements/>
  </task>
  ...
<tasks>

그리고 백업 파일 :

<tasks>
  <task id="1" >
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
      <CipherData>
        <CipherValue>+asd+c2voJ/sdf+8KukZEKJmM8=</CipherValue>
      </CipherData>
    </EncryptedData>
    <AnotherElements/>
  </task>
  <task id="2" >
   <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
      <CipherData>
        <CipherValue>+asd+c2voJ/sdf+8KukZEKJmM8=</CipherValue>
      </CipherData>
    </EncryptedData>
    <AnotherElements/>
  </task>
  ...
<tasks>

원본 파일에 오류가있는 경우 원본 파일 의 백업 파일에서 <EncryptedData>모든 <EncryptedData>요소 를 대체하고 싶은 요소 이기 때문 입니다.

그렇게하는 가장 좋은 방법은 무엇입니까?

jdweng

linq 조인 사용

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;


namespace ConsoleApplication1
{
    class Program
    {
        const string origXml = @"c:\temp\test1.xml";
        const string backupXml = @"c:\temp\test2.xml";
        static void Main(string[] args)
        {
            XDocument origDoc = XDocument.Load(origXml);

            XDocument backupDoc = XDocument.Load(backupXml);

            var groups = (from orig in origDoc.Descendants("task")
                          join backup in backupDoc.Descendants("task") on (int)orig.Attribute("id") equals (int)backup.Attribute("id")
                          select new { orig = orig, backup = backup }).ToList();

            foreach (var group in groups)
            {
                group.orig.Descendants().Where(x => x.Name.LocalName == "CipherValue").FirstOrDefault().Value = 
                    (string)group.backup.Descendants().Where(x => x.Name.LocalName == "CipherValue").FirstOrDefault();  
            }
        }
    }

}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

TOP 리스트

  1. 1

    PrematureCloseException : 연결이 너무 일찍 닫혔습니다.

  2. 2

    MDRotatingPieChart를 회전하면 각도 대신 x / y 위치가 변경됩니다.

  3. 3

    c # 웹 사이트에서 텍스트를 복사하는 방법 (소스 코드 아님)

  4. 4

    jfreecharts에서 x 및 y 축 선을 조정하는 방법

  5. 5

    ArrayBufferLike의 typescript 정의의 깊은 의미

  6. 6

    Ionic 2 로더가 적시에 표시되지 않음

  7. 7

    복사 / 붙여 넣기 비활성화

  8. 8

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  9. 9

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  10. 10

    QT Designer를 사용하여 GUI에 이미지 삽입

  11. 11

    java Apache POI Word 기존 테이블 셀 스타일 및 서식이있는 행 삽입

  12. 12

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

  13. 13

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  14. 14

    C # HttpWebRequest 기본 연결이 닫혔습니다. 전송시 예기치 않은 오류가 발생했습니다.

  15. 15

    어떻게 같은 CustomInfoWindow 다른 이벤트를 할 수 있습니다

  16. 16

    rclone으로 원격 디렉토리의 모든 파일을 삭제하는 방법은 무엇입니까?

  17. 17

    dataSnapShot.getValue () 반환 데이터베이스에 그겁니다 데이터 종료 널 (null)

  18. 18

    ORA-12557 TNS : 프로토콜 어댑터를로드 할 수 없습니다

  19. 19

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  20. 20

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  21. 21

    C # Asp.net 웹 API-JSON / XML 변환기 API 만들기

뜨겁다태그

보관