XmlWriter - 无法弄清楚如何创建此元素 [英] XmlWriter - can't figure out how to create this element

查看:51
本文介绍了XmlWriter - 无法弄清楚如何创建此元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**免责声明**我需要创建的元素可能不是有效的XML,但

这不是我的错,我正在遵循所需的集成格式

项目。


我已经使用XmlWriter很好地创建了99%的XML,有一行

我可以弄清楚如何生成:

< ServicesCertifiedMail =" OFF DeliveryConfirmation = QUOT; ON" >< / Services>


我尝试了几种不同的方法组合,但似乎无法生成该字符串。可能吗?如果是这样,任何人都知道我需要什么?
呢?我尝试调用WriteString,但它取代了<>字符用

别的东西。


感谢阅读,

Steve

**Disclaimer** The element I need to create might not be valid XML, but
it''s not my fault, I''m following a required format for an integration
project.

I''ve got 99% of the XML created nicely using XmlWriter, there is one line
that I can''t figure out how to generate:
<ServicesCertifiedMail="OFF" DeliveryConfirmation="ON" ></Services>

I''ve tried several different combinations of methods and can''t seem to
generate that string. Is it possible? If so, anyone know what I need to
do? I tried calling WriteString but it replaced the "<>" characters with
something else.

Thanks for reading,
Steve

推荐答案

你试过WriteRaw()吗?

Marc

Have you tried WriteRaw()?

Marc


sklett< ; s@s.comwrote:
sklett <s@s.comwrote:

**免责声明**我需要创建的元素可能不是有效的XML,但

it 这不是我的错,我正在按照所需的格式进行整合

项目。
**Disclaimer** The element I need to create might not be valid XML, but
it''s not my fault, I''m following a required format for an integration
project.



嗯,它绝对不是XML,并且不能被任何

XML解析器解析。 br />

如果你需要编写非XML,我建议你使用除了
XmlWriter之外的东西 - 同时向管理层(或任何人)强调它是'' sa

非常可怕的文件格式。


另一种选择是写真实文件格式。 XML然后是第二个进程

它采用了真正的XML并生成了所需的伪XML。就这样

你仍然可以使用真正的XML进行大部分处理,这可能很好。

使事情变得更容易。


- -

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复该群组,请不要给我发邮件

Well, it''s definitely not XML, and won''t be able to be parsed by any
XML parser.

If you need to write non-XML, I suggest you use something other than an
XmlWriter - while stressing to management (or whoever) that it''s a
pretty horrible file format.

One alternative would be to write "real" XML and then a second process
which took the real XML and generated the required pseudo-XML. That way
you could still use real XML for most of the processing, which may well
make things easier.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


嗨Narc,


我昨晚错过了WriteRaw(),谢谢你的建议!我只是

尝试了它,它确实写出了我给它的确切字符串,但带有一个

奇怪的副作用:对WriteElementString的所有后续调用都是

一个接一个地放在同一行。

这是一个例子:

< PackageType> RECTPARCEL< / PackageType>

将WeightOz> 1.7< / WeightOz>

将宽度大于10< /宽度>

将长度大于10< /长度>

< Depth> 10< / Depth>

< ServicesCertifiedMail =" OFF" DeliveryConfirmation = QUOT; ON" >< /服务及GT;

将值及GT; 0.00< /值及GT;<描述>销售订单#

531< /说明>< ReferenceID> 531< ; / ReferenceID>

以<< Services ..."开头。一切都在投入

同一条线。我尝试重置格式化但是没有任何

的差异。以下代码似乎导致了问题:

< code>

writer.WriteElementString(" PackageType"," RECTPARCEL");

writer.WriteElementString(QUOT; WeightOz" ;, package.Weight.ToString());

writer.WriteElementString(QUOT;宽度"," 10");

writer.WriteElementString(" Length"," 10");

writer.WriteElementString(" Depth"," 10");


//< ServicesCertifiedMail =" OFF" DeliveryConfirmation = QUOT; ON" >< / Services>

//这是一个非标准元素(我认为)所以我只是将字符串

literal转储到文件中<登记/>
writer.WriteRaw(Environment.NewLine);

writer.WriteRaw(QUOT;< ServicesCertifiedMail = \" OFF\" DeliveryConfirmation = \" ON \
Hi Narc,

I somehow missed WriteRaw() last night, thanks for the suggestion! I just
tried it and it does write out the exact string I''ve given it, but with a
strange side effect: All subsequent calls to WriteElementString are being
placed on the same line, one after another.
Here is an example:
<PackageType>RECTPARCEL</PackageType>
<WeightOz>1.7</WeightOz>
<Width>10</Width>
<Length>10</Length>
<Depth>10</Depth>
<ServicesCertifiedMail="OFF" DeliveryConfirmation="ON" ></Services>
<Value>0.00</Value><Description>Sales Order#
531</Description><ReferenceID>531</ReferenceID>
After the lined starting with "<Services..." everything is getting throw on
the same line. I tried resetting the formating but that didn''t make any
difference. Here is the code that seems to be causing the problem:
<code>
writer.WriteElementString("PackageType", "RECTPARCEL");
writer.WriteElementString("WeightOz", package.Weight.ToString());
writer.WriteElementString("Width", "10");
writer.WriteElementString("Length", "10");
writer.WriteElementString("Depth", "10");

// <ServicesCertifiedMail="OFF" DeliveryConfirmation="ON" ></Services>
// This is a non-standard element (I think) so I''m just dumping the string
literal into the file
writer.WriteRaw(Environment.NewLine);
writer.WriteRaw("<ServicesCertifiedMail=\"OFF\" DeliveryConfirmation=\"ON\"

>< / Services>");
></Services>");



writer.WriteRaw(Environment.NewLine);

writer.Formatting = Formatting.Indented;


writer.WriteElementString(QUOT;值"," 0.00");

writer.WriteElementString(QUOT;描述" ;, package.ReferenceLine1);

作家.WriteElementString(" ReferenceID",

fulfillment.SalesOrder.TransactionNumber);

< / code>


你呢看到任何会导致作者不写线的东西
$ $ $ $ $ $ $ $ $ $ $ $

感谢任何想法,

Steve


" Marc Gravell" < ma ********** @ gmail.comwrote in message

news:11 ******************** **@r19g2000prf.googlegr oups.com ...

writer.WriteRaw(Environment.NewLine);
writer.Formatting = Formatting.Indented;

writer.WriteElementString("Value", "0.00");
writer.WriteElementString("Description", package.ReferenceLine1);
writer.WriteElementString("ReferenceID",
fulfillment.SalesOrder.TransactionNumber);
</code>

Do you see anything there that would cause the writer to not write line
breaks after the call to WriteRaw()?

Thanks for any ideas,
Steve

"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@r19g2000prf.googlegr oups.com...


你试过WriteRaw()吗?


Marc
Have you tried WriteRaw()?

Marc



这篇关于XmlWriter - 无法弄清楚如何创建此元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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