如何在c#中将SGML文件转换为xml [英] How to convert SGML files to xml in c#

查看:137
本文介绍了如何在c#中将SGML文件转换为xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在紧急要求中使用code.Cant转换XML格式的SGML文件。使用任何转换器包。我需要什么呢?如果有任何机构已经处理过这个问题或者有任何想法,请回复。

I m in urgent requirement to convert the SGML file in XML using code.Cant use any converter packs. What all I need for this? please reply if any body have worked on this or have any idea.

protected void btUpload_Click(object sender, EventArgs e)
       {
           string fullFilePath = null;
           if (flImport.HasFile)
           {
               string fileName = string.Empty;
               string extension = string.Empty;
               string path = string.Empty;
               fileName = flImport.PostedFile.FileName;
               string flFilePath = Server.MapPath("Files/" + fileName);
               flImport.SaveAs(Server.MapPath("Files/" + fileName));
               fullFilePath = flFilePath;
               extension = Path.GetExtension(fileName);
               path = fileName;
               if (string.Equals(extension, ".Sgml") )
               {
                   ckContent.Text = ConvertSGMLToXml(fullFilePath );
               }
           }
       }





这里我需要写一个代码函数ConvertSGMLToHtml(fullFilePath)



here i need to write a code for the function ConvertSGMLToHtml(fullFilePath )

推荐答案

如果您只想查看文件的内容,可以使用嵌入式IE浏览器并将文档文本设置为文件内容。这适用于SGML,XML和HTML。



如果您需要特殊格式化文件内容,可以使用XSLT进行转换。

除非你有一个通用的文件结构,否则你将不得不为每个结构创建一个XSLT文件。

学习XSLT有点威胁,但最后它节省了大量的时间根据我的经验。

XSLT教程 [ ^ ]





另一种选择是自己解析文档,但这有很多工作,特别是如果你有不同的文件结构。
If you only want to view the contents of the file, you can use an embedded IE browser and set the document text to the file contents. This works for SGML, XML and HTML.

If you need special formatting of the file contents you can use XSLT to do the transform.
Unless you have a generic file structure, you will have to create an XSLT file for each structure.
It is a bit of a threashold to learn XSLT, but in the end it saves a lot of time in my experience.
XSLT Tutorial[^]


Another option is to parse the document yourself, but that is a LOT of work especially if you have different file structures.


如果有任何人有这个答案,请帮助。我也有同样的要求。
If any one has this answer please help. I am also in same requirement.


这篇关于如何在c#中将SGML文件转换为xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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