XmlTextReader的 [英] XmlTextReader

查看:55
本文介绍了XmlTextReader的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

XmlTextReader时NodeType和Text之间是否有任何关系?


文档在使用xmltextreader时使用select / case。 br />

虽然reader.Read()

Select Case reader.NodeType

Case XmlNodeType.Element

Console.Write("< {0}>",reader.Name)

Case XmlNodeType.Text

Console.Write(reader.Value)

Case XmlNodeType.CDATA

Console.Write("<![CDATA [{0}]]>",reader.Value)

Case XmlNodeType.ProcessingInstruction

Console.Write("<?{0} {1}?>",reader.Name,

reader.Value )

Case XmlNodeType.Comment

Console.Write("<! - {0} - >",reader.Value)

Case XmlNodeType.XmlDeclaration

Console.Write("<?xml version ='''1.0''?>")

Case XmlNodeType。文件

案例XmlNodeType.DocumentType

Con sole.Write("<!DOCTYPE {0} [{1}]",reader.Name,

reader.Value)

Case XmlNodeType.EntityReference

Console.Write(reader.Name)

Case XmlNodeType.EndElement

Console.Write("< / {0}>" ;,reader.Name)

结束选择

结束时

这似乎需要大量编码来关联元素

及其文本。


也许我应该调查另一个班级?


谢谢

Slonocode

Is there any relation between the NodeType and the Text when using the
XmlTextReader?

The documentation uses select/case while using the xmltextreader.

While reader.Read()
Select Case reader.NodeType
Case XmlNodeType.Element
Console.Write("<{0}>", reader.Name)
Case XmlNodeType.Text
Console.Write(reader.Value)
Case XmlNodeType.CDATA
Console.Write("<![CDATA[{0}]]>", reader.Value)
Case XmlNodeType.ProcessingInstruction
Console.Write("<?{0} {1}?>", reader.Name,
reader.Value)
Case XmlNodeType.Comment
Console.Write("<!--{0}-->", reader.Value)
Case XmlNodeType.XmlDeclaration
Console.Write("<?xml version=''1.0''?>")
Case XmlNodeType.Document
Case XmlNodeType.DocumentType
Console.Write("<!DOCTYPE {0} [{1}]", reader.Name,
reader.Value)
Case XmlNodeType.EntityReference
Console.Write(reader.Name)
Case XmlNodeType.EndElement
Console.Write("</{0}>", reader.Name)
End Select
End While
This would seem to require a great deal of coding to associate an Element
with its Text.

Perhaps I should investigate a different class?

Thanks
Slonocode

推荐答案

使用 XmlTextReader?
Is there any relation between the NodeType and the Text when using the
XmlTextReader?



糟糕。我的意思是说......在使用XmlTextReader时,元素与它之间有什么关系吗?

文本?



Oops. I meant to say...Is there any relation between an Element and it''s
Text when using the XmlTextReader?



您好Sonocode,


如果您只使用元素,我认为最简单的是数据集

with

ds.writexml(path),之后是xmldocument,带有doc.save(路径),如果它

则不可能我会选择xmltextwriter


只是我的意见


Cor
Hi Sonocode,

If you are using only elements, in my opinion the most easy is the dataset
with
ds.writexml(path), after that the xmldocument, with doc.save(path) and if it
then is impossible I would choise the xmltextwriter

Just my opinion

Cor




" Cor" < no*@non.com>在消息中写道

news:eP ************* @tk2msftngp13.phx.gbl ...

"Cor" <no*@non.com> wrote in message
news:eP*************@tk2msftngp13.phx.gbl...
Hi Sonocode,
如果你只使用元素,在我看来最简单的是数据集
ds.writexml(path),之后是xmldocument,带有doc.save(path)和如果
那么我就不可能选择xmltextwriter

只是我的意见

Cor
Hi Sonocode,

If you are using only elements, in my opinion the most easy is the dataset
with
ds.writexml(path), after that the xmldocument, with doc.save(path) and if it then is impossible I would choise the xmltextwriter

Just my opinion

Cor




你好Cor,


我真的只需要从URL读取xml提要并选择我想要的

信息。我不需要写任何xml。


通用示例:


< Cars>

< Car> Volkswagon< / Car>

< Car> Ford< / Car>

< / Cars>


我需要阅读文件,以便我知道Volkswagon和Ford都是汽车。


我希望这可以澄清它。


也许Xpath上课会更好吗?


Slonocode




Hello Cor,

I really only need to read an xml feed from a URL and pick out the
information that I want. I don''t need to write any xml.

Generic Example:

<Cars>
<Car>Volkswagon</Car>
<Car>Ford</Car>
</Cars>

I need to read the file such that I know that Volkswagon and Ford are cars.

I hope this clarifies it.

Maybe Xpath class would be better?

Slonocode



这篇关于XmlTextReader的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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