如何从xml代码中读取值 [英] how to read values from xml code

查看:129
本文介绍了如何从xml代码中读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#从以下代码中读取urdu文本。



  <   owl:DatatypeProperty     rdf:about   = & untitled-ontology-23;حے_رابطہ >  
< rdf:type rdf:resource = & owl; FunctionalProperty / >
< span class =code-keyword>< rdfs:domain rdf:resource = & untitled-ontology-23;کنٹیکٹ / >
< rdfs:range rdf:resource = & xsd;字符串 / >
< / owl:DatatypeProperty >









有谁能告诉我怎么读测试在C#中使用xml。

解决方案

请参阅 https ://www.google.com/search?q = xmlreader%20c%23 [ ^ ]。


缺少RDF名称空间声明。您只能在声明名称空间的更广泛的上下文(如果存在)中解析此XML。您可以忽略该问题并以硬编码方式识别标签,但这不正确。



要使Urdu工作,您需要使用Unicode。在后一种情况下,人们将文件保存为UTF-8编码,最实用的是。那么 XML prolog 应该是

 <? xml version =   1.0 encoding =   utf-8 ?>  





.NET FCL提出了不同的XML解析方法。这是我对它们的简短概述:



  1. 使用 System.Xml.XmlDocument class 。它实现了DOM接口;如果文档的大小不是太大,这种方式是最简单和最好的。
    参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx
  2. 使用类 System.Xml .XmlTextReader ;这是最快的阅读方式,特别是你需要跳过一些数据。
    参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx
  3. 使用类 System.Xml.Linq .XDocument ;这是类似于 XmlDocument 的最合适的方式,支持LINQ to XML Programming。
    参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx http://msdn.microsoft.com/en-us/library/bb387063.aspx




  4. -SA


i want to read urdu text from the following code using C#.

<owl:DatatypeProperty rdf:about="&untitled-ontology-23;حے_رابطہ">
        <rdf:type rdf:resource="&owl;FunctionalProperty"/>
        <rdfs:domain rdf:resource="&untitled-ontology-23;کنٹیکٹ"/>
        <rdfs:range rdf:resource="&xsd;string"/>
    </owl:DatatypeProperty>





can anyone please tell me how to read test using xml in C#.

解决方案

See https://www.google.com/search?q=xmlreader%20c%23[^].


RDF namespace declarations are missing. You can only parse this XML in wider context (if it exists), where the namespaces are declared. You can ignore the problem and recognize the tags in hard-coded way, but that would not be correct.

To make Urdu work, you need to use Unicode. In post cases, people save the file in the UTF-8 encoding, most practical one. Then XML prolog should be

<?xml version="1.0" encoding="utf-8"?>



.NET FCL suggests different ways of XML parsing. This is my short overview of them:


  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx.
  2. Use the class System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx.
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx, http://msdn.microsoft.com/en-us/library/bb387063.aspx.



—SA


这篇关于如何从xml代码中读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆