1
下面給出的是我的示例XML:分組中的XML到它們的父節點的特定節點
<Response>
<Transactions>
<Upload>
<DocumentID>1</DocumentID>
<Name>A</Name>
<DocumentID>2</DocumentID>
<Name>B</Name>
</Upload>
<Upload>
<DocumentID>3</DocumentID>
<Name>C</Name>
<DocumentID>4</DocumentID>
<Name>D</Name>
</Upload>
<Upload>
<DocumentID>5</DocumentID>
<Name>E</Name>
<DocumentID>6</DocumentID>
<Name>F</Name>
</Upload>
<Transactions>
</Response>
下面給出的是我來輸出:
<Total>
<DocumentID>1</DocumentId>
<DocumentID>2</DocumentId>
<DocumentID>3</DocumentId>
<DocumentID>4</DocumentId>
<DocumentID>5</DocumentId>
<DocumentID>6</DocumentId>
</Total>
我使用下面給出的代碼讓我輸出:
var downloadfolder = @"C:\Users\KUMARMOHANTA\Desktop\New folder\test.xml";
var masterfile = new XDocument();
XElement newDocument = new XElement("Total");
masterfile.Add(newDocument);
XDocument xdoc = XDocument.Load(downloadfolder);
masterfile.Root.Add(xdoc.Descendants("DocumentId"));
masterfile.Save(@"C:\Users\KUMARMOHANTA\Desktop\merged_.xml");
但我希望的輸出應該是這樣的:
<Total>
<Transactions>
<Upload>
<DocumentID>1</DocumentID>
<DocumentID>2</DocumentID>
</Upload>
<Upload>
<DocumentID>3</DocumentID>
<DocumentID>4</DocumentID>
</Upload>
<Upload>
<DocumentID>5</DocumentID>
<DocumentID>6</DocumentID>
</Upload>
<Transactions>
</Total>