开发者

Convert data objects to XML for use with XSLT

I am making a customer profile A how they are header and data about each visit. I have gotten my data straight into one of many data objects PersonHeader ph, and StoreVisits sv:

oCustDetails = ActiveCustDetails.GetActiveCustDetails(custNumber, Convert.ToString(regionNumber));

    ph.FirstName = oCustDetails.firstName;
开发者_运维百科    ph.LastName = oCustDetails.lastName;
    ph.MiddleName = oCustDetails.miName;
    ph.Height = oCustDetails.height;
    ph.Weight =oCustDetails.weight; 

List<sv> you get the idea.

Now how can I load these two objects into a

XmlDocument personVisits = new XmlDocument();

personVisits.Load(  ??? )

Do I have to write these data objects to disk to read into personVists?

I also need to associate an xslt file for presentation. Can that be done in the same conversion to xmlDoc or do I come back in a second pass for that?


You can serialize the CustDetails class into XML using the XMLSerializer and create the output file after the transform using the XslCompiledTransform

XmlSerializer serializer = new XmlSerializer(typeof (CustDetails));
MemoryStream stream = new MemoryStream();
serializer.Serialize(stream, oCustDetails);
stream.Position = 0;
XmlReader reader = XmlReader.Create(stream);
XmlWriter writer = XmlWriter.Create(outputPath);
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(stylesheet);
transform.Transform(reader, writer);
reader.Close();
writer.Close();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜