如何在c#中创建此消息 [英] How to create this message in c#

查看:55
本文介绍了如何在c#中创建此消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <   TOA     xmlns:xsi   =  http ://www.w3.org/2001/XMLSchema-instance    xmlns:xsd   =  http://www.w3.org/2001/XMLSchema >  
< MDF_TOA_ID > 5 < / MDF_TOA_ID >
< TOA_ID > 12345 < / TOA_ID >
< 状态 < span class =code-keyword>> InProgress < /状态 >
< 原因 < span class =code-keyword>> 取消TOA < /原因 < span class =code-keyword>>
< MessageMode > 取消< / MessageMode < span class =code-keyword>>
< / TOA >







i wan t在c#中创建此消息。帮我做



现在我这样做



< pre lang =xml> XmlDocument doc = new XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration(1.0,null,null);
doc.AppendChild(dec);

XmlElement rootnode = doc.CreateElement(TOA);

XmlElement childOne = doc.CreateElement(MDF_TOA_ID);
childOne.InnerText = Convert.ToString(MdfToaID);
rootnode.AppendChild(childOne);

XmlElement childTwo = doc.CreateElement(TOA_ID);
childTwo.InnerText = Convert.ToString(toa_id);
rootnode.AppendChild(childTwo);

XmlElement childThree = doc.CreateElement(Status);
childThree.InnerText = Convert.ToString(Cancel);
rootnode.AppendChild(childThree);

XmlElement childFour = doc.CreateElement(Reason);
childFour.InnerText = Convert.ToString(reason);
rootnode.AppendChild(childFour);

XmlElement childFive = doc.CreateElement(MessageMode);
childFive.InnerText = Convert.ToString(Cancel);
rootnode.AppendChild(childFive);

rootnode.AppendChild(rootnode);



doc.AppendChild(rootnode);







但这不是我想要的结果。





请帮帮我

解决方案

尝试删除:

 rootnode.AppendChild(rootnode); 





根节点不能是自己的子节点。





然后添加以下两行:

 doc.DocumentElement.SetAttribute(xmlns:xsi,http://www.w3.org/2001/XMLSchema-instance); 
doc.DocumentElement.SetAttribute(xmlns:xsd,http://www.w3.org/2001/XMLSchema);





在 <$ i $ c> c> doc.AppendChild(rootnode);


之后添加

<TOA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MDF_TOA_ID>5</MDF_TOA_ID>
<TOA_ID>12345</TOA_ID>
<Status>InProgress</Status>
<Reason>Cancelling TOA</Reason>
<MessageMode>Cancel</MessageMode>
</TOA>




i want to create this message in c#.help me to do

right now i m doing this

XmlDocument doc = new XmlDocument();
        XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
        doc.AppendChild(dec);

        XmlElement rootnode = doc.CreateElement("TOA");       

        XmlElement childOne = doc.CreateElement("MDF_TOA_ID");
        childOne.InnerText = Convert.ToString(MdfToaID);
        rootnode.AppendChild(childOne);

        XmlElement childTwo = doc.CreateElement("TOA_ID");
        childTwo.InnerText = Convert.ToString(toa_id);
        rootnode.AppendChild(childTwo);

        XmlElement childThree = doc.CreateElement("Status");
        childThree.InnerText = Convert.ToString("Cancel");
        rootnode.AppendChild(childThree);

        XmlElement childFour = doc.CreateElement("Reason");
        childFour.InnerText = Convert.ToString(reason);
        rootnode.AppendChild(childFour);

        XmlElement childFive = doc.CreateElement("MessageMode");
        childFive.InnerText = Convert.ToString("Cancel");
        rootnode.AppendChild(childFive);

        rootnode.AppendChild(rootnode);



        doc.AppendChild(rootnode);




but it is not my desire result.


please help me

解决方案

Try removing:

rootnode.AppendChild(rootnode);



The root node cannot be a child of itself.


Then add the following two lines:

doc.DocumentElement.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); 
doc.DocumentElement.SetAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");



Add this after doc.AppendChild(rootnode);


这篇关于如何在c#中创建此消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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