Suppose I have two XML files.
First XML File:
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
<AccessLicenseNumber>Your_License</AccessLicenseNumber>
<UserId>Your_ID</UserId>
<Password>Your_Password</Password>
</AccessRequest>
Second XML File:
<?xml version="1.0"?>
<RatingServiceSelectionRequest xml:lang="en-US">
<CustomerContext>Rating and Service</CustomerContext>
</RatingServiceSelectionRequest>
Now, when I merge them two, i want the output like this:
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
<AccessLicenseNumber>Your_License</AccessLicenseNumber>
<UserId>Your_ID</UserId>
<Password>Your_Password</Password>
</AccessRequest>
<?xml version="1.0"?>
<RatingServiceSelectionRequest xml:lang="en-US">
<CustomerContext>Rating and Service</CustomerContext>
</RatingServiceSelectionRequest>
When I am merging these two files using the usual methods found on google, the version number etc are being eaten up and RatingServiceSelectionRequest node ends up being part of AccessRequest node, which is clearly not what I want.
How do I approach this in C#.Net?
Note: The reason I want it like that is because this API I’m using is requesting it like that, so no two ways about it I guess.
You cannot have two top-level nodes
<AccessRequest>and
<RatingServiceSelectionRequest>in a well-formed XML file – that’s by definition – a well-formed XML file has one and exactly one root node.
Also, you cannot have two XML processing instructions
<?xml version="1.0"?>in a single file – most certainly not one in the middle of the file.So you’ll need to either introduce a new, “artificial” root, or stick on XML under the other root element or something.
If you really must keep that format, then you just concatenate the two files as strings:
No XML magic here ….