Tag: xml

将CDATA附加到字符串

我的情况是我们使用合同优先方法进行Web服务。 我必须使用CDATA来避免需要附加到当前字符串变量的特殊字符。 将CDATA标记附加到当前字符串的最佳方法是什么,该字符串作为响应对象中的xml元素返回? 我们正在使用C#。

xml使用它的generics类型序列化generics类

我需要将包含Pair类型的对象的列表序列化为xml。 除了这些值,我还需要序列化它的generics类型( T和U的类型)。 首先,我创建了一个类PairList来保存对的列表,然后我创建了实际的类,它表示一对两个值,键和值。 [XmlRoot(“pairList”)] public class PairList{ [XmlElement(“element”)] public List<Pair> list; public PairList() { list = new List<Pair>(); } } public class Pair { [XmlAttribute(“key”)] public T key; [XmlAttribute(“value”)] public U value; [XmlAttribute(“T-Type”)] public Type ttype; [XmlAttribute(“U-Type”)] public Type utype; public Pair() { } public Pair(T t, U u) { key = t; value […]

更改系统托盘颜色Windows Phone

有没有办法将Windows Phone上的系统托盘颜色从黑色更改为白色? 我的应用程序有白色背景,所以我希望系统托盘也是白色的。

将Class转换为XML为string

我正在使用XMLSerializer将类序列化为XML。 有很多例子可以将XML保存到文件中。 但是我想要的是将XML放入字符串而不是将其保存到文件中。 我正在尝试下面的代码,但它不起作用: public static void Main(string[] args) { XmlSerializer ser = new XmlSerializer(typeof(TestClass)); MemoryStream m = new MemoryStream(); ser.Serialize(m, new TestClass()); string xml = new StreamReader(m).ReadToEnd(); Console.WriteLine(xml); Console.ReadLine(); } public class TestClass { public int Legs = 4; public int NoOfKills = 100; } 有想法该怎么解决这个吗 ? 谢谢。

使用属性读取XML的最简单方法

我有一个我想阅读的XML文件(使用xml atrributes)。 结构不会改变,但内容确实如此。 示例XML: http : //www.yr.no/place/Norway/Oslo/Oslo/Oslo/forecast.xml (必须手动将URL复制并粘贴到地址字段中,否则您将获得404。) 我无法使用此代码(并使用XSD.EXE)从它创建XSD: XmlTextReader myXmlTextReader = new XmlTextReader(“forecast.xml”); DataSet myDataSet = new DataSet(); myDataSet.ReadXml(myXmlTextReader); myDataSet.WriteXmlSchema(“forecast.xsd”); 结果是: 列名’name’是为不同的映射类型定义的。 现在,想象一下,我在这方面很懒,并且不想花费我的整个晚上手动将XML映射到我的对象。 我希望为我生成托管代码对象,以便我可以轻松读取数据。 我有什么选择? …如果有人知道,XSD转换错误消息是什么意思?

使用C#将XDocument或XmlDocument转换为JSON

我有这个XML很棒: 但它输出到这个JSON: {“Products”:{“Product”:[{“@ProductCode”:”C1010″,”@CategoryName”:”Coins”}, {“@ProductCode”:”C1012″,”@CategoryName”:”Coins”}, {“@ProductCode”:”C1013″,”@CategoryName”:”Coins”}]}} 我想在我的json中没有’产品’分级,因为所有三行都是产品。 这是我的C#代码: //x is an XDocument. JsonConvert.SerializeXNode(x, Formatting.None, false) //JsonConvert.SerializeXNode(x); //I also tried without the formatting and the boolean. 当我’将’XDocument’转换为XmlDocument并使用: var xmlDocument = new System.Xml.XmlDocument(); using (var xmlReader = x.CreateReader()) { xmlDocument.Load(xmlReader); } JsonConvert.SerializeXmNode(xmlDocument); 它给了我完全相同的输出。 那么如何修改我的JSON解析,以便我有一个简单的产品列表。 我更喜欢最干净的解决方案。 或许更清楚一点,我这样的东西作为输出: [{“@ProductCode”:”C1010″,”@CategoryName”:”Coins”}, {“@ProductCode”:”C1012″,”@CategoryName”:”Coins”}, {“@ProductCode”:”C1013″,”@CategoryName”:”Coins”}]

C#Linq对XML进行添加,更新,删除

我有这个代码 XElement newClient= new XElement(“Client”, new XElement(“Name”, cmbClient.Text), new XElement(“Service”, new XElement(“ServName”, cmbService.Text))); xmlDoc.Add(newClient); xmlDoc.Save(“Settings.xml”); 这创造了这个 Client Name Service Name 如果我再次按下Button1,那么它将创建另一个客户端部分,这没关系,但我想要的是: 如果不存在,请创建新的客户端部分。 如果Client存在,则向其添加 ServName,而不是替换已有的ServName。 如果客户端上已存在服务,则不执行任何操作,因为已存在。 任何线索? 我从linq开始到xml …感谢您的建议! 编辑:解决方案由mixin Dmitry Dovgopoly和Leon Newswanger提供答案谢谢你们两位! :d XDocument xDoc = XDocument.Load(“Settings.xml”); var Clients = from client in xDoc.Root.Elements(“Client”) where client.Element(“Name”).Value == cmbClient.Text select client; if (Clients.Count() > 0) { […]

如何更新XML节点?

它很容易读取XML文件并获得确切的节点文本,但如何使用新值更新该节点? 阅读: public static String GetSettings(SettingsType type, SectionType section) { XmlTextReader reader = new XmlTextReader(HttpContext.Current.Request.MapPath(APPSETTINGSPATH)); XmlDocument document = new XmlDocument(); document.Load(reader); XmlNode node = document.SelectSingleNode( String.Format(“/MyRootName/MySubNode/{0}/{1}”, Enum.Parse(typeof(SettingsType), type.ToString()), Enum.Parse(typeof(SectionType), section.ToString()))); return node.InnerText; } 来写 …? public static void SetSettings(SettingsType type, SectionType section, String value) { try { XmlTextReader reader = new XmlTextReader(HttpContext.Current.Request.MapPath(APPSETTINGSPATH)); XmlDocument document = […]

如何解析c#中的html文本

我有一个像这样的html表达式: “This is Some Text” + Environment.NewLine + “This is some more text 我只想提取文本。 所以结果应该是 “This is Some Text” + Environment.NewLine + “This is some more text” 我该怎么做呢?

当CSV包含字符和数字数据时,将CSV转换为XML

从这个线程,我得到了关于如何解析CSV以创建XML的基本信息。 不幸的是,文本字段(全部用引号括起来)有时包含逗号,所以line.split(’,’)给了我太多列。 我无法弄清楚如何解析CSV所以line.split(’,’)区分文本字段中的逗号和逗号分隔字段。 有关如何做到这一点的任何想法? 谢谢!