如何编写xml字符串 [英] How to write xml string

查看:96
本文介绍了如何编写xml字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我解决错误。我的问题是我实际上从Web服务获取xml字符串,

我将该字符串存储到XML文件中并使用xml.reader()读取文件;



但是如果有空的xml节点,节点正在单个标签中,那么将从Web服务获取字符串Ex:

 <   Data_Classification     /  >  



而不是

 <   Data_Classification  >  <   / Data_Classification  >  



以下是我写的将xml字符串存储到xml文件的代码。



代码:

 私有 静态  void  printMessage( string  strBody)
{
sring strPath = Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings [ PrintMsgPath]);
if (!Directory.Exists(strPath))
{
Directory.CreateDirectory(strPath);
}
if (!File.Exists(strPath + \\APMIRIS.xml))
{
使用(StreamWriter sw = File。 CreateText(strPath + \\APMIRIS.xml))
{
sw.WriteLine(strBody);
}
}
else
{
File.Delete(strPath + \\APMIRIS.xml);
// 使用(StreamWriter sw1 = File.Delete(strPath +\\APMIRIS.xml)) )
// {
using (StreamWriter sw2 = File.CreateText(strPath + \\APMIRIS.xml ))
{
sw2.WriteLine(strBody);
}
}
}





请告诉我哪里出错?

解决方案



< Data_Classification>< / Data_Classification>  

< data_classification /> 





XML阅读器/兼容XML标准的编写器将同等读取两个值。



欢呼,

Marco Bertschi


Please help me in solving the error. My Problem is I actually getting xml String from Web service,
I am storing that string into XML File and reading the file using xml.reader();

But will getting the string from web service if there is empty xml node the node is geting in single tag Ex:

<Data_Classification />


instead of

<Data_Classification></Data_Classification>


Following is the code I am writing to store xml string to xml file.

Code:

private static void  printMessage(string strBody)
{			 
    sring strPath =Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["PrintMsgPath"]); 
    if(!Directory.Exists(strPath))
    {
        Directory.CreateDirectory(strPath);
    }
    if (!File.Exists(strPath+"\\APMIRIS.xml")) 
    {
        using (StreamWriter sw = File.CreateText(strPath+"\\APMIRIS.xml")) 
        {				
            sw.WriteLine(strBody);				
        }	
    }
    else
    {
        File.Delete(strPath+"\\APMIRIS.xml");		
//      using (StreamWriter sw1 = File.Delete(strPath+"\\APMIRIS.xml")) 
//      {
        using (StreamWriter sw2 = File.CreateText(strPath+"\\APMIRIS.xml")) 
        {	
            sw2.WriteLine(strBody);					
        }					
    }
}



Please let me know the where I am going wrong?

解决方案

There is no actual difference between

<Data_Classification></Data_Classification>


and

<data_classification />



An XML reader/writer which is compatible with the XML standard will read both values equally.

cheers,
Marco Bertschi


这篇关于如何编写xml字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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