当我尝试从数据库Xpath XML数据时,我有这个错误(从法语Visual Studio错误翻译):System.ArgumentException:'路径中的不合规字符。 Error from Visual Studio (French)
这是我的代码:
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection connection = new SqlConnection(@"Data Source=SA2426\SQLEXPRESS;Initial Catalog=Proteor;Persist Security Info=True;User ID=sa;Password= root");
string query = "SELECT Content From Template WHERE Id = '0108f7ac-7853-4543-8ec4-a04cb755ed46' AND Deleted = '0'";
protected void Page_Load(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand(query, connection);
connection.Open();
SqlDataReader sdr = cmd.ExecuteReader();
XmlDocument doc = new XmlDocument();
if(sdr.HasRows)
{
while(sdr.Read())
{
string content = sdr["Content"].ToString();
System.Diagnostics.Debug.WriteLine(System.Web.HttpUtility.HtmlDecode(content));
// Test Decode
string contenu = System.Web.HttpUtility.HtmlDecode(content);
doc.Load(System.Web.HttpUtility.HtmlDecode(content));
XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
ns.AddNamespace("msbld", "http://schemas.microsoft.com/developer/msbuild/2003");
XmlNode FormId;
FormId = doc.SelectSingleNode("descendant::Properties/Property[attribute::Name='FormId']", ns);
System.Diagnostics.Debug.WriteLine(FormId.OuterXml);
}
}
}
finally
{
connection.Close();
}
}
}
我必须解码我的XML,因为此数据中包含特殊字符,如“&lt”,“&gt”......我不知道怎么可能...我复制/粘贴“测试解码”简单的xml文档,以便检查xml代码,它没关系:
<Root>
<StorageObject Name="OI-GENOUILLERE ODRA-v2" Id="0108f7ac-7853-4543-8ec4-a04cb755ed46" Type="Adviser.Proteor.Library.TemplateImpl">
<Properties>
<Property Name="TimeCreated" Value="27/07/2017 11:14:18" /><Property Name="Enabled" Value="True" /><Property Name="TimePublished" Value="01/01/0001 00:00:00" /><Property Name="TimeLastModified" Value="10/11/2017 09:09:29" /><Property Name="Description" Value="" /><Property Name="ObjectContent" Value=""<Template>
<Component Type="Adviser.Proteor.Library.TemplateImpl">
<ExtendedProperty Text="OI" Key="Classification" />
<ExtendedProperty Text="35176af2-b664-42d6-a7ba-5d06602b0500" Key="ClassificationId" />
<ExtendedProperty Text="GAO" Key="Activity" />
<ExtendedProperty Text="58d942ea-8cf7-4089-879c-f8633925473b" Key="ActivityId" />
<ExtendedProperty Text="OI 36" Key="AnatomicalLevel" />
<ExtendedProperty Text="76418da5-6830-4a49-aed0-b472c11c67c6" Key="AnatomicalLevelId" />
<ExtendedProperty Text="ORTHESE INF." Key="Type" />
<ExtendedProperty Text="13b33a27-57ce-4009-8812-00f8578982fd" Key="TypeId" />
<Version Version.Major="0" Version.Minor="1" />
<Properties>
<Property Name="TimeCreated" Value="27/07/2017 11:14:18" />
<Property Name="Enabled" Value="True" />
<Property Name="TimePublished" Value="01/01/0001 00:00:00" />
<Property Name="TimeLastModified" Value="10/11/2017 09:09:29" />
<Property Name="Description" Value="" />
</Properties>
<Component Type="Adviser.Proteor.Library.StepImpl">
<Properties>
<Property Name="FormId" Value="d442dce3-fc1f-49da-92c5-b25d89d76881" />
<Property Name="ValidationMode" Value="None" />
</Properties>
<Component Type="Adviser.Proteor.Library.Impl.Action.Task.OnPageLoadTrigger">
<Properties>
<Property Name="PageNumber" Value="1" />
</Properties>
<Component Type="Adviser.Proteor.Library.Impl.Action.Task.SetControlValueTask">
<Properties>
<Property Name="Text" Value="{agence}" />
<Property Name="ObjectId" Value="dc20a4e2-46d6-47fe-8c75-bf4d7ff012ba" />
</Properties>
</Component>
这不是完整的代码,但您可以看到代码是正确编写的。
需要帮忙 !!!
编辑:目前我刚看到的东西。在主xml代码中封装了一个xml代码:
ObjectContent的值不是“已完成”,而是以其他标记模板开头
根据the docs的XmlDocument.Load
,这个重载:
从指定的URL加载XML文档。
你传递的不是URL,它是包含XML内容的string
。这就是错误消息指出您的路径中包含无效字符的原因 - 您的XML根本不是路径。
您想使用XmlDocument.LoadXml
方法。