大图片问题 - 创建XML文件最干净的方法 [英] Big picture questions - cleanest method for creating an XML file

查看:46
本文介绍了大图片问题 - 创建XML文件最干净的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不习惯以编程方式创建xml文件。大图

是这样的:这将是VB / VS 2005 / winforms。我有一个DTD,一个示例XML,

和一个外部数据源,我将用它来填充XML。一般来说,我认为我知道如何创建元素和属性,我相信我可以一起破解

,但我想知道我是不是丢失(或遗忘)一个更好的

方式(除了一长串硬编码的CreateElement命令)。

建议请。


-----


一个相关的问题:XML标题,因为没有更好的术语。如果我们假设从头开始创建一个XmlDocument对象,我该如何添加标题

元素?我找不到任何关于此的讨论。 (请随意更正我的

术语。)


这就是我指的 -


<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

<!DOCTYPE SOME TEXT" DTDName.dtd">

<?xml-stylesheet href =" SampleXml.xslt"类型= QUOT;文本/ XSL" ?>

I am not accustomed to creating xml files programmatically. The big picture
is this: This will be in VB/VS 2005/ winforms. I have a DTD, a sample XML,
and an outside data source I will use to populate the XML. In general I
think I know how to create elements and attributes and I''m sure I can hack
something together but I''m wondering if I''m missing (or forgetting) a better
way (other than a long line of hard-coded CreateElement commands).
Suggestions please.

-----

A related problem: the XML header, for lack of a better term. If we assume
creation of an XmlDocument object from scratch, how do I add the header
elements? I cannot find any discussion of this. (Feel free to correct my
terminology.)

This is what I''m referring to -

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE SOME TEXT "DTDName.dtd">
<?xml-stylesheet href="SampleXml.xslt" type="text/xsl" ?>

推荐答案

关于标题,您不需要添加它。它是在序列化

文档时创建的,并不总是需要,它取决于使用的编码



我同意通过几十个CreateXXX语句创建文档不是很好。

文档的变化有多大。我经常从一个模板开始,或者是一个
字符串常量,在资源文件或实际文件中并首先加载它。

然后我根据需要改变它。 />
-


Joe Fawcett(MVP - XML)

http://joe.fawcett.name


" B。 Chernick" < BC ******* @ discussion.microsoft.com写信息

新闻:D3 ********************* ************* @ microsof t.com ...
As to the header you shouldn''t need to add it. It is created when the
document is serialised and isn''t always needed, it depends on the encoding
used.
I agree that creating documents by dozens of CreateXXX statements is not
nice.
How changeable are the documents. I often start with a template, either a
string constant, in a resource file or an actual file and load this first.
Then I alter it as needed.
--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"B. Chernick" <BC*******@discussions.microsoft.comwrote in message
news:D3**********************************@microsof t.com...

>我不习惯以编程方式创建xml文件。大图片

是这样的:这将是VB / VS 2005 / winforms。我有一个DTD,一个示例

XML,

以及我将用来填充XML的外部数据源。一般来说,我认为我知道如何创建元素和属性,我相信我可以一起破解

,但我想知道我是不是丢失(或忘记)a

更好

方式(除了一长串硬编码的CreateElement命令)。

建议请。< br $>

-----


一个相关的问题:XML标题,因为没有更好的术语。如果我们从b开始假设

创建一个XmlDocument对象,我该如何添加标题

元素?我找不到任何关于此的讨论。 (请随意更正我的

术语。)


这就是我指的 -


<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

<!DOCTYPE SOME TEXT" DTDName.dtd">

<?xml-stylesheet href =" SampleXml.xslt"类型= QUOT;文本/ XSL" ?>
>I am not accustomed to creating xml files programmatically. The big
picture
is this: This will be in VB/VS 2005/ winforms. I have a DTD, a sample
XML,
and an outside data source I will use to populate the XML. In general I
think I know how to create elements and attributes and I''m sure I can hack
something together but I''m wondering if I''m missing (or forgetting) a
better
way (other than a long line of hard-coded CreateElement commands).
Suggestions please.

-----

A related problem: the XML header, for lack of a better term. If we
assume
creation of an XmlDocument object from scratch, how do I add the header
elements? I cannot find any discussion of this. (Feel free to correct my
terminology.)

This is what I''m referring to -

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE SOME TEXT "DTDName.dtd">
<?xml-stylesheet href="SampleXml.xslt" type="text/xsl" ?>



B. Chernick写道:
B. Chernick wrote:

我不习惯以编程方式创建xml文件。大图

是这样的:这将是VB / VS 2005 / winforms。我有一个DTD,一个示例XML,

和一个外部数据源,我将用它来填充XML。一般来说,我认为我知道如何创建元素和属性,我相信我可以一起破解

,但我想知道我是不是缺少(或遗忘)一个更好的

方式(除了一长串硬编码的CreateElement命令)。

建议请。
I am not accustomed to creating xml files programmatically. The big picture
is this: This will be in VB/VS 2005/ winforms. I have a DTD, a sample XML,
and an outside data source I will use to populate the XML. In general I
think I know how to create elements and attributes and I''m sure I can hack
something together but I''m wondering if I''m missing (or forgetting) a better
way (other than a long line of hard-coded CreateElement commands).
Suggestions please.



如果将DTD转换为模式,则可以使用XML

序列化/反序列化:
http://msdn.microsoft.com/en-us/ libr ... ss(VS.80).aspx

您可以使用xsd.exe工具从架构创建.NET类。


如果你有关系数据,那么你也可以考虑填充一个

数据集并使用它的WriteXml方法。

If you convert the DTD into a schema then you can use XML
serialization/deserialization:
http://msdn.microsoft.com/en-us/libr...ss(VS.80).aspx
You can use the xsd.exe tool to create .NET classes from the schema.

If you have relational data then you can also consider to populate a
DataSet and use its WriteXml method.


这是什么我指的是 -


<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>
This is what I''m referring to -

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



这是XML声明,它是由WriteStartDocument

方法创建的XmlWriter
http://msdn.microsoft.com/en-us/libr ... tdocument.aspx

或使用CreateXmlDeclaration
http://msdn.microsoft.com/en-us/libr...claration.aspx

在DOM模型中。

That is the XML declaration, it is created by the WriteStartDocument
method of XmlWriter
http://msdn.microsoft.com/en-us/libr...tdocument.aspx
or using CreateXmlDeclaration
http://msdn.microsoft.com/en-us/libr...claration.aspx
in the DOM model.


<!DOCTYPE SOME TEXT" DTDName.dtd">
<!DOCTYPE SOME TEXT "DTDName.dtd">



这是一个文档类型声明,使用WriteDocType创建
http://msdn.microsoft.com/en-us/libr...tedoctype.aspx

of XmlWriter或使用CreateDocumentType
http://msdn.microsoft.com/en-us/libr...umenttype.aspx

XmlDocument的方法。

That is a document type declaration, created using WriteDocType
http://msdn.microsoft.com/en-us/libr...tedoctype.aspx
of XmlWriter or using CreateDocumentType
http://msdn.microsoft.com/en-us/libr...umenttype.aspx
method of XmlDocument.


<?xml-stylesheet href =" SampleXml.xslt"类型= QUOT;文本/ XSL" ?>
<?xml-stylesheet href="SampleXml.xslt" type="text/xsl" ?>



这是一个名为''xml-stylesheet''的处理指令和

数据''href =" SampleXml。 XSLT" type =" text / xsl"''所以你使用
创建它
XmlWriter的WriteProcessingInstruction
http://msdn.microsoft.com/en-us/libr...struction.aspx

或使用CreateProcessingInstruction
http://msdn.microsoft.com/en-us/libr...struction.aspx

of XmlDocument。

-


Martin Honnen --- MVP XML
http://javaScript.FAQTs.com/

That is a a processing instruction with the name ''xml-stylesheet'' and
the data ''href="SampleXml.xslt" type="text/xsl"'' so you create it using
WriteProcessingInstruction of XmlWriter
http://msdn.microsoft.com/en-us/libr...struction.aspx
or using CreateProcessingInstruction
http://msdn.microsoft.com/en-us/libr...struction.aspx
of XmlDocument.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


我不是故意粗鲁,但我害怕我不明白很多你的回复。


据我所知,这不是标准的Dot Net情况。这个程序的目的是如果有的话,就是从Excel中提取数据,然后将它插入一个独立的XML文件中。我很害怕我已经很少了。我认为它最终被送入了一些大型机系统。


" Joe Fawcett"写道:
I don''t mean to be rude but I''m afraid I didn''t understand much your reply.

This, so far as I know, is not a standard Dot Net situation. The purpose of
the program, if it ever gets written, is to extract data from an Excel
spreadsheet and plug it into a standalone XML file. I''m afraid I''ve been
given very little of the big picture. I think it eventually gets fed into
some mainframe system.

"Joe Fawcett" wrote:

至于标题,你不需要添加它。它是在序列化

文档时创建的,并不总是需要,它取决于使用的编码



我同意通过几十个CreateXXX语句创建文档不是很好。

文档的变化有多大。我经常从一个模板开始,或者是一个
字符串常量,在资源文件或实际文件中并首先加载它。

然后我根据需要改变它。 />

-

Joe Fawcett(MVP - XML)

http://joe.fawcett.name


" B。 Chernick" < BC ******* @ discussion.microsoft.com写信息

新闻:D3 ********************* ************* @ microsof t.com ...
As to the header you shouldn''t need to add it. It is created when the
document is serialised and isn''t always needed, it depends on the encoding
used.
I agree that creating documents by dozens of CreateXXX statements is not
nice.
How changeable are the documents. I often start with a template, either a
string constant, in a resource file or an actual file and load this first.
Then I alter it as needed.
--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"B. Chernick" <BC*******@discussions.microsoft.comwrote in message
news:D3**********************************@microsof t.com...

我不习惯以编程方式创建xml文件。大的

图片

是这样的:这将是VB / VS 2005 / winforms。我有一个DTD,一个示例

XML,

以及我将用来填充XML的外部数据源。一般来说,我认为我知道如何创建元素和属性,我相信我可以一起破解

,但我想知道我是不是丢失(或忘记)a

更好

方式(除了一长串硬编码的CreateElement命令)。

建议请。< br $>

-----


一个相关的问题:XML标题,因为没有更好的术语。如果我们从b开始假设

创建一个XmlDocument对象,我该如何添加标题

元素?我找不到任何关于此的讨论。 (请随意更正我的

术语。)


这就是我指的 -


<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

<!DOCTYPE SOME TEXT" DTDName.dtd">

<?xml-stylesheet href =" SampleXml.xslt"类型= QUOT;文本/ XSL" ?>
I am not accustomed to creating xml files programmatically. The big
picture
is this: This will be in VB/VS 2005/ winforms. I have a DTD, a sample
XML,
and an outside data source I will use to populate the XML. In general I
think I know how to create elements and attributes and I''m sure I can hack
something together but I''m wondering if I''m missing (or forgetting) a
better
way (other than a long line of hard-coded CreateElement commands).
Suggestions please.

-----

A related problem: the XML header, for lack of a better term. If we
assume
creation of an XmlDocument object from scratch, how do I add the header
elements? I cannot find any discussion of this. (Feel free to correct my
terminology.)

This is what I''m referring to -

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE SOME TEXT "DTDName.dtd">
<?xml-stylesheet href="SampleXml.xslt" type="text/xsl" ?>






这篇关于大图片问题 - 创建XML文件最干净的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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