XML到纯文本 [英] XML to plain text

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

问题描述

我有一个简单的xml文件,其中部分包含HTML格式的内容。我

包含<![cdata []]>中的内容标签。这很好。


但是,我的应用程序需要输出XML文件(从强类型的
数据集)到纯文本。我正在做


theText = myDataset.getXML()


哪个有效,但它没有记住 cdata标签中的部分,

以便解析内容,将每个html标签转换为& lt; b& gt;等等...


是否有一种简单的方法可以在不解析数据的情况下输出数据,并强制某些节点使用cdata标签? getXML函数不接受

参数。


谢谢!


MCD

I have a simple xml file that contains, in part, content that is in HTML. I
am encompassing that content in <![cdata[]]> tags. This works fine.

However, my application needs to output the XML file (from a strongly typed
dataset) to plain text. I am doing

theText = myDataset.getXML()

Which works, but it doesn''t "remember" the portions that were in cdata tags,
so that content gets parsed, turning every html tag int &lt;b&gt;, etc...

Is there a simple way to output that data without parsing it, and forcing
certain nodes to use the cdata tag? The getXML function accepts no
parameters.

Thanks!

MCD

推荐答案

因为我相信这个问题在五秒内无法解决,所以尝试:

theText = Replace(theText,"<"" ,"& lt;")

theText = Replace(theText,">","& gt;")

Big D < a@a.com>在消息中写道

news:%2 ****************** @ TK2MSFTNGP10.phx.gbl ...
Since I believe this issomething which can''t get fixed in five seconds try:
theText =Replace(theText, "<", "&lt;")
theText =Replace(theText, ">", "&gt;")

"Big D" <a@a.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
我有一个简单的xml文件,其中部分包含HTML格式的内容。
我在<![cdata []]>中包含该内容标签。这很好。

但是,我的应用程序需要输出XML文件(从强大的
类型数据集)到纯文本。我正在做

theText = myDataset.getXML()

哪个有效,但它并没有记住在cdata
标签中的部分,以便解析内容,将每个html标签转换为& lt; b& gt;等等...

有没有简单的方法输出该数据而不解析它,并强制某些节点使用cdata标签? getXML函数不接受
参数。

谢谢!

MCD
I have a simple xml file that contains, in part, content that is in HTML. I am encompassing that content in <![cdata[]]> tags. This works fine.

However, my application needs to output the XML file (from a strongly typed dataset) to plain text. I am doing

theText = myDataset.getXML()

Which works, but it doesn''t "remember" the portions that were in cdata tags, so that content gets parsed, turning every html tag int &lt;b&gt;, etc...

Is there a simple way to output that data without parsing it, and forcing
certain nodes to use the cdata tag? The getXML function accepts no
parameters.

Thanks!

MCD



嗨BigD,


您的意思是这个吗?


\\\它开始制作样本数据集

Dim ds作为新数据集

Dim dt As New DataTable(" parameters")

for c As Integer = 1 To 10

Dim dc As New DataColumn(" elem" c.tostring)

dt.Columns.Add(dc)

Next

对于r作为整数= 1到10

Dim dr As DataRow = dt.NewRow

对于c as Integer = 1到10

dr(elem& c.tostring)= _

r.ToString& c.tostring''或者只是dr(c)但是要告诉你

下一页

dt.Rows.Add(dr)''也可以之前但我发现这个看起来更好

下一页

ds.Tables.Add(dt)

- 结束建筑样本数据集

Dim ser作为XmlSerializer = New XmlSerializer(GetType(DataSet))

Dim ms As New IO.MemoryStream

Dim sw As IO.TextWriter = New IO.StreamWriter(ms)

ser.Serialize(sw,ds)

Dim b As Long = ms.Length

ms.Position = 0

Dim sr As IO.TextReader = New IO.StreamReader(ms)

Dim xmlstring As String = sr.ReadToEnd

sw.Close()

sr.Close()

ms.Close()

///

我希望这有点帮助?​​


Cor
Hi BigD,

Did you mean this?

\\\It start with making a sample dataset
Dim ds As New DataSet
Dim dt As New DataTable("parameters")
For c As Integer = 1 To 10
Dim dc As New DataColumn("elem" & c.tostring)
dt.Columns.Add(dc)
Next
For r As Integer = 1 To 10
Dim dr As DataRow = dt.NewRow
For c As Integer = 1 To 10
dr("elem" & c.tostring) = _
r.ToString & c.tostring '' or just dr(c) but to show you
Next
dt.Rows.Add(dr) '' can also before but I find this looking nicer
Next
ds.Tables.Add(dt)
-- end building sample dataset
Dim ser As XmlSerializer = New XmlSerializer(GetType(DataSet))
Dim ms As New IO.MemoryStream
Dim sw As IO.TextWriter = New IO.StreamWriter(ms)
ser.Serialize(sw, ds)
Dim b As Long = ms.Length
ms.Position = 0
Dim sr As IO.TextReader = New IO.StreamReader(ms)
Dim xmlstring As String = sr.ReadToEnd
sw.Close()
sr.Close()
ms.Close()
///
I hope this helps a little bit?

Cor




嗨大D,


我已审核过您的问题。我将花一些时间对这个问题进行一些研究。


我会尽快回复你。感谢您的理解。


祝你好运,

Jeffrey Tan

Microsoft在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有赋予任何权利。


Hi Big D,

I have reviewed your issue. I will spend some time to do some research on
this issue.

I will reply to you ASAP. Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


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

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