C# Xml dom manipulation (merge)

Bohica69

Gawd
Joined
Jul 12, 2005
Messages
676
I've got to XML dom's that I want to do a merge on and don't exactly know where to start - I feel this has to be possible, but can't find any examples anywhere.

One DOM is an HTML document - It might look something like this:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
</head>
<body>
Thank you for contacting <CompanyName />. We here at <CompanyName /> look forward to helping you with your requirements. Please contact us at
<CompanyAddress1 />
<CompanyAddress2 />
<CompanyCity />&nbsp;<CompanyState/>, <CompanyZip/>
</body>
</html>

The other Dom looks like this
Code:
<CompanyData>
     <CompanyName>SomeCompany</CompanyName>
     <CompanyAddress1>123 Main</CompanyAddress1>
     <CompanyAddress2>Suite A</CompanyAddress2>
     <CompanyCity>Seattle</CompanyCity>
     <CompanyState>WA</CompanyState>
     <CompanyZip>98345</CompanyZip>
</CompanyData>

What I need is some C# code to merge these two dom together substituting the values in the second dom for the nodes in the first dom where appropriate... Yes I know I could do a search and replace, but I'm wondering if there's a way to do it with the XML objects in C#?

Any help is as usual, appreciated.
 
I haven't really worked with XML in c# too much, but isn't there an InnerXML and InnerText attribute that you can read and write to?

ie. "Thank you for contacting " + companyData.InnerXML("CompanyName") + ". We...".

Basically you'd be looking up a specific attribute of <CompanyData> and outputting it. Then at the end, write the final file (if that's what you need to do).
 
Yea, that will work, but I was wondering if there was some transform type function that would make this easier.

Anybody? Anybody? Bueller?
 
Back
Top