Hi,
I'm trying to select specific nodes from a XmlDocument filled with a
serialized object and to insert these nodes into another XmlDocument.
The object is well serialized (see below). From a normal XmlDoc to
another I don't have any issue, the nodes are copied but then with this
serialized object it doesn't seem to work.
The C# code:
XmlSerializer serializer = new XmlSerializer(typeof(BusinessList));
//Main document we want the nodes to be copied
XmlDocument docMain=new XmlDocument();
docMain.Load(HttpContext.Current.Server.MapPath("X ML/page.xml"));
//Selection the root node of the main element
XmlNode newNode=docMain.SelectSingleNode("page");
//XmlDoc to load the serialized object
XmlDocument docObject=new XmlDocument();
//Stream to transfert the serialized object
MemoryStream inputStream = new MemoryStream();
//Serialize object to inputStream
serializer.Serialize(inputStream, myBusinesses);
inputStream.Seek(0, SeekOrigin.Begin);
//Load XML Document from Memory
docObject.Load(inputStream);
//Selection the appropriate nodes list in the serialized object
XmlNodeList nodeList=docObject.SelectNodes("//businessInfos");
foreach (XmlNode listChild in nodeList)
{
XmlNode listChildImport = docMain.ImportNode(listChild, true);
newNode.AppendChild(listChildImport);
}
//Save XML to file to check
them docObject.Save(HttpContext.Current.Server.MapPath( "XML/test.xml"));
docMain.Save(HttpContext.Current.Server.MapPath("X ML/test2.xml"));
Serialized object (part):
<?xml version="1.0"?>
<businessList xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" generic="2.0"
operator="Microsoft Corporation" truncated="true"
xmlns="urn:uddi-org:api_v2">
<businessInfos>
<businessInfo businessKey="fe3f2397-63a9-4670-882a-837fa1cf452d">
<name xml:lang="en">#minds DMS (Document Management
System)</name>
<description xml:lang="en">We are a group of two students (Stefan
Kugele, Stephan Thoma) participating in an UDDI/SOAP/VS.NET/Web Service
programming contest at the Technical University of Munich,
Germany</description>
<serviceInfos>
<serviceInfo serviceKey="29c4d875-9c14-4ba9-a44b-605165466740"
businessKey="fe3f2397-63a9-4670-882a-837fa1cf452d">
<name xml:lang="en">GetDocuments</name>
</serviceInfo>
</serviceInfos>
</businessInfo>
Thx in advance for your ideas and solutions.