gpt4 book ai didi

.net - 为什么我的 XmlReader 会返回一个空字符串?

转载 作者:数据小太阳 更新时间:2023-10-29 02:02:24 25 4
gpt4 key购买 nike

我需要从 XmlReader 获取完整的 Xml 字符串(长话短说)。不过,在此示例代码中,最终变量 theXmlString 仍为空。为什么没有为它分配 Xml 字符串?

string xmlConfig = @"<pdfMappings>
<pdfFile formTypeEnum=""Int_UT_Additional_Investment_Form_Ind_And_LE_direct"">
<perspective ngiAdminPerspectiveName=""Investor"">
<fieldMapping fieldName=""topmostsubform[0].Page2[0].first_names[0]"" mapTo=""CurrentInvolvedParty.FirstName""></fieldMapping>
<fieldMapping fieldName=""topmostsubform[0].Page2[0].surname[0]"" mapTo=""CurrentInvolvedParty.LastName""></fieldMapping>
</perspective>
</pdfFile>
</pdfMappings>";
var reader = XmlReader.Create(new StringReader(xmlConfig));

string theXmlString = reader.ReadOuterXml();

最佳答案

只需要先开始读取,使用Read()移动到节点,然后使用ReadOuterXml()真正读取值。

var reader = XmlReader.Create(new StringReader(xmlConfig));
reader.Read();
string theXmlString = reader.ReadOuterXml();

或者,您还应该能够使用 reader.MoveToContent();

关于.net - 为什么我的 XmlReader 会返回一个空字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9515823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com