Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XmlDocument.Save()

Status
Not open for further replies.

markknowsley

Programmer
Aug 30, 2005
152
GB
I've written a method which takes an XmlDocument passed from a Biztalk orchestration and then appends some information to the XmlDocument.

I now want to save the changes that I have made to the document and send the modified document back to Biztalk. The document is in memory - I don't want to output it to a physical location so XmlDocument.Save("mydoc.xml") is no good. How can I save the changes to the document when it's 'in memory'?

Cheers,

Mark.
 
since you received the XMLDocument from biztalk; is there an function in the biztalk API that will accept an XMLDocument to save? or is this what you are creating?

here is a snippet to loop through the document and get the string value. I wrote this from scratch, so it's prone to errors.
Code:
public class XmlUtilities
{
public string NodeToString(XmlNode node)
{
   StringBuilder toReturn = new StringBuilder();
   
      toReturn.Append("<");
      toReturn.Append(node.Name);
      toReturn.Append(this.AttributesToString(node));
      toReturn.Append(">");
      toReturn.Append(node.InnerText);
      foreach(XmlNode child in node.ChildNodes)
      {
         toReturn.Append(this.NodeToString(child));
      }
      toReturn.Append("</");
      toReturn.Append(node.Name);
      toReturn.Append(">");
   }

   return toReturn.ToString();
}
public string AttributesToString(XmlNode node)
{
   StringBuilder toReturn = new StringBuilder();
   foreach(XmlAttribute attribute in node.Attributes)
   {
      toReturn.Append(string.Format(" {0}=\"{1}\"", attribute.Key, attribute.Value));
   }

   return toReturn.ToString();
}
}
you can access it like this
Code:
XmlUtilities utility  = new XmlUtilities();
string xmlstring = utility.NodeToString(myXmlDocument.DocumentElement);

//save xmlstring to biztalk

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks for the effort - I solved this by:
1. Creating a variables of type System.XML.XmlDocument in the Biztalk orchestration (DocIn).
2. I set DocIn to the value of the Biztalk message, passed this into a method, used the method to query a database and append the XML and then returned the updated XML document.
3. Then I set the content of the Biztalk message to be the same as the newly updated XmlDocument.

Biztalk seemed to like this and the output was correct, so problem solved!

 
that sounds much more elegant than my approach :)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
jmeckley,

That looks like a lot of work. Doesn't this do the same thing?

Code:
string xmlstring = myXmlDocument.OuterXml;
 
yeah, your right. outerxml would be much cleaner. In reading the help file I assumed it was not recursive.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top