Xdocument不打印声明 [英] Xdocument does not print declaration

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

问题描述

我尝试使用domainpeople.com API,并且需要使用XML.

I try to use the domainpeople.com API and to do I need to use XML.

当前我有一个错误消息,提示找不到apiProtocol",我想我的Xml文档格式错误.

Currently I have an error saying "apiProtocol is not found" I guess then that my Xml document is malformed.

发送的当前xml是:

<apiProtocol version="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNameSpaceSchemaLocation="checkrequest.xsd">
  <checkRequest user="ifuzion" password="fish4gold121" reference="123456789">
    <domain name="google.com" /> 
  </checkRequest>
</apiProtocol>

显然,<?xml?>部分没有打印出来.

Apparently the <?xml?> part does not print out.

我的代码基本上类似于:

My code is basically something similar to :

XDocument xDocument = new XDocument(
new XDeclaration("1.0", "UTF-8", "yes"),
new XElement("Books"));

(出于简单性考虑,我剥离了代码,但结构完全相似).

(I stripped my code for a question of simplicity but the structure is exactly similar).

是否有任何原因导致XDocument无法打印出<?xml?>部分?似乎使用XmlDocument可以使用,但不能与XDocument一起使用...有任何提示吗?

Is there any reason why XDocument doesn't print out the <?xml?> part ? It seems that with XmlDocument it works but not with XDocument ... any hints ?

推荐答案

如何打印出XDocument的内容?

.ToString()方法不包括xml标头,但是.Save()方法包括.

The .ToString() method does not include the xml header, but the .Save() method does.

编辑: 查看全文

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