我需要C#xml生成帮助.我不想在xml中使用一些参数 [英] i need help C# xml genaration. i don't want some arguments in xml

查看:108
本文介绍了我需要C#xml生成帮助.我不想在xml中使用一些参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <? xml version = "  1.0" encoding =   utf-8" standalone = "  ?> 
<   FormData  > 
<  已注册 >  1 <  /已注册 > 
<  版本 >  1 <  /版本 > 
<   FormId/ > 
<  侧面 >  1 <  /侧面 > 
<   SubForms  >  0 <  /SubForms  > 
<  角度 >  = 0.001 <  /Angle  > 
<  来源    ="   0.117"  Y    0.027" / > 
<   RegistrationMark     ="   1.317"  TopLeftY   > 2.043"     TopRightX   ="  7.100"  TopRightY    2.047"  BottomLeftX   ="     BottomLeftY   ="  3.073"  BottomRightX   ="     ="   3.077" >  


这是C#中生成的xml.在那个

 <? xml version = "  encoding = "  standalone = "  ?> 


encoding ="utf-8" standalone ="yes"?我不想要此参数,我们如何可以在不使用此参数的情况下对xml进行变性.只有我想要

 <? xml version = "  1.0" 解决方案

<情况正好相反:我不知道您在XML序言中如何最终获得独立"属性.我必须承认,我以前从未遇到过这个神秘的"(见下文)属性,因为在标准库中找到的所有直接产生XML的方法都不会产生该属性,除非您有意创建它.

有关此属性及其用途,请参见 http://www.xmlplease.com/standalone [ http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [http://msdn.microsoft.com/en-us/library/bb387063.aspx [ XDocument doc = XDocument(); doc.Save();



我相信,如果您不指定新的XDeclaration,它将不会设置任何内容.我的建议是尝试上面的代码并查看您的文件以查看其中的内容.


<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<FormData>
<Registered>1</Registered>
<Version>1</Version>
<FormId/>
<Sides>1</Sides>
<SubForms>0</SubForms>
<Angle>=0.001</Angle>
<Origin X="0.117" Y="0.027"/>
<RegistrationMark TopLeftX="1.317" TopLeftY="2.043" TopRightX="7.100" TopRightY="2.047" BottomLeftX="1.313" BottomLeftY="3.073" BottomRightX="7.097" BottomRightY="3.077"/>


This is the generated xml in c#. In that

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


encoding="utf-8" standalone="yes"? i don''t want this parameter how we can genarate xml with out this parameter. only i want

<?xml version="1.0"?>

like this

The situation is directly opposite: I have no idea how you ended up with the "standalone" attribute in the XML prolog. I must confess I never faced with this "mysterious" (see below) attribute before, as all direct ways to produce XML found in the standard libraries won''t produce this attribute, unless you intentionally create it, of course.

About this attribute and its use, please see
http://www.xmlplease.com/standalone[^].

By the way, I don''t know why this attribute can do anything wrong. But of course, you have every right to avoid having it.

So, just in case, let me overview all standard methods of working with XML directly. Of course, this review does not include various forms of serialization (which you might have faces with) or Data Contract (which I always highly recommend). Let''s see:


  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the classes System.Xml.XmlTextWriter and System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].



—SA


All that does is defines the document.

XDocument doc = new XDocument();
doc.Save();



I believe that if you don''t specify a new XDeclaration, it will not set any of that stuff. My suggestions is to try the code above and loo at your file to see what''s in it.


这篇关于我需要C#xml生成帮助.我不想在xml中使用一些参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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