惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
博客园_首页
WordPress大学
WordPress大学
博客园 - 聂微东
P
Privacy International News Feed
Forbes - Security
Forbes - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes
月光博客
月光博客
NISL@THU
NISL@THU
美团技术团队
T
Tailwind CSS Blog
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Hacker News
The Hacker News
B
Blog
P
Palo Alto Networks Blog
L
Lohrmann on Cybersecurity
有赞技术团队
有赞技术团队
The Register - Security
The Register - Security
S
Securelist
A
Arctic Wolf
MyScale Blog
MyScale Blog
H
Help Net Security
N
Netflix TechBlog - Medium
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Threatpost
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Latest
Security Latest
T
Tor Project blog
V
Vulnerabilities – Threatpost
V
V2EX
AI
AI
Hugging Face - Blog
Hugging Face - Blog
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
Simon Willison's Weblog
Simon Willison's Weblog
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Heimdal Security Blog
Google Online Security Blog
Google Online Security Blog
Know Your Adversary
Know Your Adversary

博客园 - 心利

DocOptimizer 0.9.0 Beta Released SharePoint GroupedItemPicker Control Drag & Drop between SharePoint Document libraries Improving SharePoint User Experience With JQuery-Client Side Form Validate SharePoint How To:定位错误:“An SPRequest object was not disposed .." SharePoint Tips and Tricks --如何用JS向PeopleEditor填充数据 SharePoint Tips and Tricks -- Ribbon,People Editor 使用T4为数据库自动生成实体类(C#) (Tips&Tricks)用客户端模板精简JavaScript代码 (Tips &Tricks)如何为Windows Mobile 创建拨号连接--C# Windows Ce vs Windows Mobile Asp.net程序中生成Excel报表 My Page StartKit项目概览 做一个更好的程序员 .Net类库中实现的HashTable 为Asp.net控件写单元测试(ViewState) 使用Control Adapters优化Asp.net控件 ViewState 简述一(With Example And Apply to Asp.net) 桌面背景:rss新闻阅读器(图)
System.Xml FAQ Part 1
心利 · 2008-10-28 · via 博客园 - 心利

   作为一项单独的任务,最近XML小组收到一个问题列表。我们觉得这个列表很有借鉴意义,因为许多用户遇到的困难都是它们导致的。这些问题既有冷僻方法的调用,也有复杂XML的构建,但是我们将注意力集中在了一些真正难以调试的场景。当完成这个任务以后,我们想,应该把它们公布出来。

Q1: 特殊字符   

        有一些特殊字符作为保留字不能在XML中使用,比如"&"、“<”。XML标准有三种方法可以解决这个问题:转义字符、实体参考、CDATA .

        OK,这个问题对于有经验的用户来说,像是基本的XML101,但是对于新用户来说可能就是一个噩梦。问题之所以复杂化了,是因为XML 解析器通常返回令人迷惑的错误信息。这个错误也是新用户经常遇到的,因为通常待使用的文本往往包含这些特殊字符。这些字符是:

  • &   (&amp;)
  • <    (&lt;)
  • >    (&gt;)
  • ‘    (&apos;)
  • “   (&quot;)

下面是几个包含了这些特殊字符的字符串,以及相应的异常信息。这些异常都包含行号和列号,可以辅助你找到错误。

Character String

Correct Usage

Exception Message

A & B

A &amp; B

An error occurred while parsing EntityName. Line X, position Y.  

A &c B

A &amp;c B

' ' is an unexpected token. The expected token is ';'. Line X, position Y.

A &# B

A &amp;# B

Invalid syntax for a decimal numeric entity reference. Line X, position Y.

A < B

A &lt; B

Name cannot begin with the ' ' character, hexadecimal value 0x20. Line X, position Y.

Q2: XML 片段

有时候你可能需要解析一些不符合标准的XML片段,比如一个没有根节点的XML字符串,例如:

“<foo></foo><bar></bar>”

如果你把这个XML片段当做XmlReader的参数,你会得到一个异常:

“There are multiple root elements. Line X, position Y.”

这个异常设计的非常好,它准确说明了发生的错误:一个XML文档只能有一个根节点。但是如果你真的想解析这类XML该怎么做呢?看下面的代码:

string xmlFragmentStr = "<foo></foo><bar></bar>";
//create a reader settings objects and set the conformance level to

fragment
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.ConformanceLevel = ConformanceLevel.Fragment;
//create a reader using the reader settings
XmlReader r = XmlReader.Create(new StringReader(xmlFragmentStr),

xrs);
r.Read();

PS One:

Some future FAQ post topics include but are not limited to:

-          Reporting Validation Warnings

-          Correct Encodings

-          ProhibitDTD setting

-          XLinq Bridge Classes

PS Two:

不知道大家有没有人对校内网感兴趣。校内网上的应用 现在也有很多很多了。小弟最近想做一个LINQ TO XiaoNei,就是一个Linq Provider,可以让开发者用C# Linq feature,操作校内网数据(用户,朋友,通知之类的)。正在恶补XML。。。。