110 likes | 210 Views
Programação com XML e XSLT. Web Control XML – System.Web.UI.WebControls.XML Use the Xml control to display the contents of an XML document without formatting or using XSL Transformations. XmlDocument – XslTransform Transformação de um documento XML Display num Web XML control
E N D
Web Control XML – System.Web.UI.WebControls.XML • Use the Xml control to display the contents of an XML document without formatting or using XSL Transformations.
XmlDocument – XslTransform • Transformação de um documento XML • Display num Web XML control XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath("people.xml")); XslTransform trans = new XslTransform(); trans.Load(Server.MapPath("peopletable.xsl")); xml1.Document = doc; xml1.Transform = trans; Exemplo
Preencher DataSet com XML • Método ReadXml • XmlTextReader string pathname=Server.MapPath("produtos.xml"); XmlTextReader tr=new XmlTextReader(pathname); mydataset=new DataSet(); mydataset.ReadXml(tr); DataGrid1.DataSource=mydataset; DataGrid1.DataBind();
Process XML Data In-Memory • Discusses the two models for processing XML data. The XmlDocument class, and its associated classes, is based on the W3C Document Object Model. The XPathDocument class is based on the XPath data model. • http://msdn2.microsoft.com/en-us/library/2bcctyt8.aspx • http://msdn2.microsoft.com/en-us/library/534aacaa.aspx
Migrating from Version 1.1 of the XML Classes • http://msdn2.microsoft.com/en-us/library/534aacaa.aspx
The XslCompiledTransform class is the new XSLT processor. It replaces the XslTransform class. The XsltSettings enumeration is used to enable optional XSLT settings such as support for embedded scripts or the XSLT document() function. • Version 1.1
Criar XML com informação de um DataSet (1) • Método WriteXml oleDbDataAdapter1.Fill(dataset); string name=tbName.Text; string path=Server.MapPath("."); string filepath=path+"\\ " + name; dataset.WriteXml(filepath); • Vários overload: DataSet.WriteXml (String) DataSet.WriteXml (XmlWriter, XmlWriteMode) …
Criar XML com informação de um DataSet (2) • Método GetXml do DataSet • Class XPathNavigator • Provides a cursor model for navigating and editing XML data. • Class XPathDocument • Provides a fast, read-only, in-memory representation of an XML document using the XPath data model. string strxml = dataset.GetXml(); StringReader str=new StringReader(strxml); XPathDocument docpath = new XPathDocument(str); XPathNavigator nav=docpath.CreateNavigator(); Xml1.XPathNavigator = nav; Xml1.DataBind();
Actualizar BD com documento XML – (tabela Produtos) string pathname2= Server.MapPath("produtos2.xml"); DataSet novo=new DataSet(); novo.ReadXml(pathname2); oleDbDataAdapter1.Update(novo,"Produtos");
Transformações XSLT • Class XslCompileTransform • Microsoft .NET Framework XSLT processor. This class is used to compile style sheets and execute XSLT transformations.