0
在我的項目中,我使用包含二進制格式圖像的linq,xml文件訪問xml文件數據。如何在xml文件中用linq到xml訪問圖像
我想讀取該XML文件,並將該圖像的XML文件分配給我的窗體上的圖片框。
但是我不能做到這一點:雖然我對XML應用查詢文件它沒有任何元素理解數據類型...
問題是什麼?
這是我的示例XML文件&代碼在C#::
/////////xml file agency.xml////////////
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="agency">
<xs:complexType>
<xs:sequence>
<xs:element name="no" type="xs:int" minOccurs="0" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="Slogan" type="xs:string" minOccurs="0" />
<xs:element name="Vatno." type="xs:int" minOccurs="0" />
<xs:element name="MainBranch" type="xs:string" minOccurs="0" />
<xs:element name="Disclaimer" type="xs:string" minOccurs="0" />
<xs:element name="Logo" type="xs:base64Binary" minOccurs="0" />
<xs:element name="street" type="xs:string" minOccurs="0" />
<xs:element name="town_x002F_city" type="xs:string" minOccurs="0" />
<xs:element name="State_x002F_Country" type="xs:string" minOccurs="0" />
<xs:element name="PostalCode" type="xs:int" minOccurs="0" />
<xs:element name="Phone1" type="xs:int" minOccurs="0" />
<xs:element name="Phone2" type="xs:int" minOccurs="0" />
<xs:element name="Fax" type="xs:int" minOccurs="0" />
<xs:element name="Emailid" type="xs:string" minOccurs="0" />
<xs:element name="Website" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<agency>
<no>1</no>
<Name>Good Deal Pvt</Name>
<Slogan>We Values of Your Money</Slogan>
<Vatno.>123</Vatno.>
<MainBranch>Your Branch One</MainBranch>
<Disclaimer>All the information is legal still the buyer should collect other details if needed. This intended to give information & not part of any agreement.</Disclaimer>
<Logo>here is actually that lengthy binary data for image, i have edit that </Logo>
<street>Link Raod, Near Satara Road,Pune</street>
<town_x002F_city>Pune</town_x002F_city>
<State_x002F_Country>Mahrastra</State_x002F_Country>
<PostalCode>231231</PostalCode>
<Phone1>1231313</Phone1>
<Phone2>12312323</Phone2>
<Fax>1231231</Fax>
<Emailid>[email protected]</Emailid>
<Website>www.gooddeal.com</Website>
</agency>
</NewDataSet>
////////sample code c# code to access above xml file//////////
XDocument doc = XDocument.Load("c:\\xml1\\agency.xml");
var result = from agen in doc.Descendants("agency")
where (int)agen.Element("no") == 1
select// agen;
new
{
no = (string)agen.Element("no"),
Name =(string) agen.Element("Name"),
Slogan = (string)agen.Element("Slogan"),
logo = agen.Element("Logo")
};
foreach (var tuple in result)
{
textbox1.text=tuple.Name;
textbox2.text=tuple.Slogan;
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(tuple.logo.ToString()));
Bitmap bmap = new Bitmap(ms);
this.pictureBox1.Image = bmap;
}