编写xml并附带条件阅读 [英] write an xml and read with a condition
本文介绍了编写xml并附带条件阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
海,
我想创建一个具有以下结构的xml文件
Hai,
I would like to create an xml file with the following structure
<?xml version="1.0"?>
<Category>Mobile Phones
<Subcategory>Samsung Phones
<Brand>Samsung
<Product>
<title>SAMSUNG B7722I WHITE DUALSIM SAMSUNG B7722I WHITE DUALSIM
</title>
<Network>GSM 850 / 900 / 1800 / 1900 - SIM 1 </Network>
<Dimensions>113.5 x 55.5 x 14.3 mm Greutate : 112 g Weight: 112 g </Dimensions>
<Camera>5 MP, 2560x1920 pixels, LED flash </Camera>
<Radio>Stereo FM radio with RDS, FM recording </Radio><Standby>Up to 420 h </Standby>
<TalkTime>Up to 12 h 50 min</TalkTime>
</Product>
<Product>
<title>
SAMSUNG GALAXY S WIFI 4.0 WHITE
</title>
<Network>N / A </Network>
<Weight> </Weight>
<Camera>3.15 MP, 2048x1536 pixels, autofocus, LED flash </Camera>
<Radio>Stereo FM radio with RDS </Radio>
</Product>
</Brand>
</Subcategory>
<Subcategory>
NOKIA Phones
<Brand>
Nokia
<Product>
<title>
NOKIA N8 PINK
</title>
<Network>GSM 850 / 900 / 1800 / 1900 </Network>
<Dimensions>113.5 x 59.1 x 12.9 mm, 86 cc </Dimensions>
<Camera>5 MP, 2560x1920 pixels, LED flash </Camera>
<Standby>Up to 420 h </Standby>
<TalkTime>Up to 12 h 50 min</TalkTime>
<weight>135 g</weight>
<Rooms>12 MP, 4000x3000 pixels, Carl Zeiss optics, autofocus, Xenon flash </Rooms>
<Radio>Stereo FM radio with RDS, FM transmitter </Radio>
</Product> </Brand>
</Subcategory>
</Category>
我想显示XML文件,如以下链接所示,并带有特定条件,例如subcategory =诺基亚电话或三星电话
http: //translate.google.com/translate?hl=zh-CN&sl=ro&tl=en&u=http%3A%2F%2Fwww.quickmobile.ro%2Ftelefoane-nokia [
I would like to show the xml file like the following link with a specific condition like subcategory= nokia phone or samsung phone
http://translate.google.com/translate?hl=en&sl=ro&tl=en&u=http%3A%2F%2Fwww.quickmobile.ro%2Ftelefoane-nokia[^]
How its possible
pls help
Thank you,
soumya
推荐答案
您可以使用 LINQ to XML [ ^ ]来创建/modify和删除XML中的元素.
使用LINQ to XML,您可以像下面这样轻松创建XML:
You can use LINQ to XML[^] to create/modify and delete elements in XML.
With LINQ to XML you can easy create XML like this:
XElement xmlTree1 = new XElement("Root",
new XElement("Child1", 1),
new XElement("Child2", 2),
new XElement("Child3", 3),
new XElement("Child4", 4),
new XElement("Child5", 5),
new XElement("Child6", 6)
);
输出为:
And output is:
<Root>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
</Root>
希望它能为您提供帮助.
Hope it can help you.
正如Kim所说 LINQ to XML [ ^ ]很好.但是,如果您想使用面向对象的方法,请 XML序列化 [
As Kim said LINQ to XML[^] is good. But if you want to work with OO way, then XML Serialization[^] is way to go.
I hope this helps you well.
我还建议XSLT作为有条件地呈现XML并将其转换为更易于阅读的方式.您没有说,但我想您不想显示原始XML?
I would also suggest XSLT as a way of rendering XML conditionally, and converting it to be more human readable. You don''t say, but I assume you don''t want to show raw XML ?
这篇关于编写xml并附带条件阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文