// MsXmlTest.cpp : ¶¨Òå¿ØÖÆ̨ӦÓóÌÐòµÄÈë¿Úµã¡£
//
#include "stdafx.h"
#include "MsXmlTest.h"
#include <clocale>
#include "comutil.h"
#import "msxml4.dll"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// ΨһµÄÓ¦ÓóÌÐò¶ÔÏó
CWinApp theApp;
using namespace std;
void WritePerson(MSXML2::IXMLDOMDocument2Ptr pDocument, MSXML2::IXMLDOMNodePtr pParentNode, CString name, long age)
{
//´´½¨Ò»¸ö<Person>½Úµã
MSXML2::IXMLDOMElementPtr pPersonNode = pDocument->createElement(_T("person"));
pParentNode->appendChild(pPersonNode);
//дÈëname
MSXML2::IXMLDOMElementPtr pPersonNameNode = pDocument->createElement(_T("name"));
pPersonNameNode->text = _bstr_t(name);
//дÈëage
MSXML2::IXMLDOMElementPtr pPersonAgeNode = pDocument->createElement(_T("age"));
pPersonAgeNode->text = _bstr_t(age);
pPersonNode->appendChild(pPersonNameNode);
pParentNode->appendChild(pPersonAgeNode);
}
void WritePersons()
{
MSXML2::IXMLDOMDocument2Ptr pXMLDocume ......
Integration with the XML Data Type
With the introduction of the XML data type, we wanted to also give FOR XML the ability to generate an instance of XML directly (more precisely, it generates a single row, single column rowset where the cell contains the XML data type instance).
Because of the backwards-compatibility considerations outlined above, we added a new TYPE directive to generate the result as XML. For example,
Copy
SELECT * from Customers FOR XML AUTO, TYPE
returns the Customers elements as an XML data type instance, instead of the nvarchar(max) instance that would have been the case without the TYPE directive.
This result is guaranteed to conform to the well-formedness constraints provided by the XML data type. Since the result is an XML data type instance, you can also use XQuery expressions to query and reshape the result. For example, the following expression retrieves the Customer contact name into a new Person element.
Copy
SELECT (SELECT * from Customers FOR XM ......
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace jiufen.Web.code
{
public class OperatingXML
{
XmlDocument xmlDoc = new XmlDocument();
//load xml file
private void LoadXml()
{
xmlDoc = new XmlDocument();
xmlDoc.Load(HttpContext.Current.Server.MapPath("xml/User.xml"));//xmlµÄ¸ùĿ¼
}
//Ìí¼Ó½Úµã
public void AddElement()
{
LoadXml();
XmlNode xmldocSelect = xmlDoc.SelectSingleNode("user");
XmlElement el = xmlDoc.CreateElement("person"); //Ìí¼Óperson½Úµã
el.SetAttribute("name", "ÖܽÜÂ×"); //Ìí¼Óperson½ÚµãµÄÊôÐÔ"name"
el.SetAttribute("sex", "ÄÐ"); //Ìí¼Óperson½ ......
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace jiufen.Web.code
{
public class OperatingXML
{
XmlDocument xmlDoc = new XmlDocument();
//load xml file
private void LoadXml()
{
xmlDoc = new XmlDocument();
xmlDoc.Load(HttpContext.Current.Server.MapPath("xml/User.xml"));//xmlµÄ¸ùĿ¼
}
//Ìí¼Ó½Úµã
public void AddElement()
{
LoadXml();
XmlNode xmldocSelect = xmlDoc.SelectSingleNode("user");
XmlElement el = xmlDoc.CreateElement("person"); //Ìí¼Óperson½Úµã
el.SetAttribute("name", "ÖܽÜÂ×"); //Ìí¼Óperson½ÚµãµÄÊôÐÔ"name"
el.SetAttribute("sex", "ÄÐ"); //Ìí¼Óperson½ ......
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace jiufen.Web.code
{
public class OperatingXML
{
XmlDocument xmlDoc = new XmlDocument();
//load xml file
private void LoadXml()
{
xmlDoc = new XmlDocument();
xmlDoc.Load(HttpContext.Current.Server.MapPath("xml/User.xml"));//xmlµÄ¸ùĿ¼
}
//Ìí¼Ó½Úµã
public void AddElement()
{
LoadXml();
XmlNode xmldocSelect = xmlDoc.SelectSingleNode("user");
XmlElement el = xmlDoc.CreateElement("person"); //Ìí¼Óperson½Úµã
el.SetAttribute("name", "ÖܽÜÂ×"); //Ìí¼Óperson½ÚµãµÄÊôÐÔ"name"
el.SetAttribute("sex", "ÄÐ"); //Ìí¼Óperson½ ......
package test;
import java.util.ArrayList;
import java.util.List;
import org.nuxeo.common.xmap.annotation.XNode;
import org.nuxeo.common.xmap.annotation.XNodeList;
import org.nuxeo.common.xmap.annotation.XObject;
/**
* Book ʵÌå¶ÔÏ󣬴˴¦ÓÃXMap×¢½â
* @author Administrator
*
*/
@XObject
public class Book {
@XNode("title")
private String title;
@XNode("@no")
private String no;
@XNodeList(value = "subject", type = ArrayList.class, componentType = String.class)
private List<String> subjects;
@XNode("price")
private int price;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<String> getSubjects() {
return subjects;
}
public void setSubjects(List<String> subjects) {
this.subjects = subj ......
package test;
import java.util.ArrayList;
import java.util.List;
import org.nuxeo.common.xmap.annotation.XNode;
import org.nuxeo.common.xmap.annotation.XNodeList;
import org.nuxeo.common.xmap.annotation.XObject;
/**
* Book ʵÌå¶ÔÏ󣬴˴¦ÓÃXMap×¢½â
* @author Administrator
*
*/
@XObject
public class Book {
@XNode("title")
private String title;
@XNode("@no")
private String no;
@XNodeList(value = "subject", type = ArrayList.class, componentType = String.class)
private List<String> subjects;
@XNode("price")
private int price;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<String> getSubjects() {
return subjects;
}
public void setSubjects(List<String> subjects) {
this.subjects = subj ......
µ±Äã½âÎöXMLʱ£¬ÊÇ·ñ»áÒòΪÃüÃû¿Õ¼äµÄ´æÔÚ¶ø²»Äܵó¥ËùÔ¸ÄØ£¿
java·½Ã棬ºÃ¶àÈËÍƼöÓÃdom4j´¦Àíxml£¬ÎÒÒ²¾Í˵˵ÔÚdom4jÉÏ´¦Àí´øÃüÃû¿Õ¼äµÄxml
xml´úÂëexample: ÔÙ˵ǰÈýÖÖ·½·¨£¬Ò²ÊÇ´ÓÍøÉÏ¿´À´µÄ¡£http://www.cnblogs.com/patrickchen/articles/1188920.html
D: eport.css
µÚÒ»¸ö·½°¸.ÉèÖÃÄãµÄxpathµÄÃüÃû¿Õ¼äsetNamespaceURIs
1: public class TransferXML { 2: public static void main(String[] args) throws Exception{ 3: Map map = new HashMap(); 4: map.put("design","http://www.eclipse.org/birt/2005/design"); 5: SAXReader saxReader = new SAXReader(); 6: File file = new File("D:\test.xml"); 7: Document document = saxReader.read(file); 8: XPath x = document.createXPath("//design:list-property"); 9: x.setNamespaceURIs(map); 10: List nodelist = x.selectNodes(document); 11: System.out.println(nodelist.size()); 12: } 13: }
µÚ¶þ¸ö½â¾ö·½°¸:ÉèÖÃÄãµÄDocumentFactory()µÄÃüÃû¿Õ¼ä setXPathNamespaceURIs
1: publi ......
string GetXmlByDataTable()
{
string xmlstr;
string sql = "select top 10 * from BasicInfo";
DataTable dt = idb.ReturnDataTable(sql);
dt.TableName = "tbname";
if (dt.Rows.Count>0)
{
System.IO.StringWriter writer = new System.IO.StringWriter();
dt.WriteXml(writer);
xmlstr = writer.ToString();
}
return xmlstr;
} ......