将XMl节点值显示到消息框 [英] Display XMl node Value to a Message Box

查看:68
本文介绍了将XMl节点值显示到消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI家伙我卡住了,需要一些帮助



我需要从下面的XML中获取NodeNotificationContentTxt的值

 <?  xml     version   =  1.0    encoding   =  UTF-8  >  
<! - XMLSpy v2014 rel生成的XML文件示例。 2(http://www.altova.com) - >
< n1:FATCAFileErrorNotification xmlns = urn:fatca:fatcanotificationbase xmlns:n1 = urn:fatca :fatcafileerrornotification xmlns:xsi = http://www.w3.org/2001/XMLSchema-instance version = 1.4 >
< FATCANotificationHeaderGrp >
< < span class =code-leadattribute> FATCANotificationCreateTs > 2014-11-14T00:00:00Z < ; / FATCANotificationCreateTs >
< FATCANotificationRefId > Notif12345 < ; / FATCANotificationRefId >
< FATCANotificationCd > NDC < ; / FATCANotificationCd >
< FATCAEntitySenderId > 000000.00000.TA.840< / FATCAEntitySenderId >
< FATCAEntityReceiverId > S519K4.99999.SL.392 < / FATCAEntityReceiverId >
< CopiedToFATCAEntityId > 000000.00000.TA.392 < / CopiedToFATCAEntityId >
< ContactInformationTxt > http://www.irs.gov/Businesses/Corporations/FATCA-Error-Notifications < / ContactInformationTxt >
< / FATCANotificationHeaderGrp >
< OriginalFileMetadataGrp >
< IDESTransmissionId > a7c6363de36f4c2192856b4d3283747c < / IDESTransmissionId >
< IDESSendingTs > 2014-11-10T00:00:00Z < / IDESSendingTs >
< OriginalIDESTransmissionId > c646151fe7ed4bd696efc8efe49226ac < / OriginalIDESTransmissionId >
< SenderFileId > SenderFile1 < / SenderFileId >
< UncompressedFileSizeKBQty > 100000 < / UncompressedFileSizeKBQty >
< / OriginalFileMetadataGrp >
< NotificationContentTxt > IRS解密引用的文件失败。请参考文件请求的操作。< / NotificationContentTxt >
< ActionRequestedGrp >
< ActionRequestedTxt > 重新提交文件。< / ActionRequestedTxt >
< ActionRequestedDueDateTxt > 您的组织提交表格8966的截止日期。< / ActionRequestedDueDateTxt >
< / ActionRequestedGrp >

< / n1:FATCAFileErrorNotification >



我一直收到构建错误,我的C#代码低于

 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;
使用 System.Xml;


命名空间 WindowsFormsApplication6
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click( object <> span sender,EventArgs e)
{


OpenFileDialog ofd = new 打开文件对话框();
ofd.Filter = XML | * .xml;
if (ofd.ShowDialog()== DialogResult.OK)
{
XmlDocument xDoc = XmlDocument();
xDoc.Load(ofd.FileName);
MessageBox.Show(xDoc.SelectSingleNode( FATCAFileErrorNotification / NotificationContentTxt)。InnerText);
}
}

}
}



先谢谢

试试这个:

 System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); 
xml.Load(@dirve:\ path \ file.xml);
System.Xml.XmlElement root = xml.DocumentElement;
System.Xml.XmlNodeList list = root.GetElementsByTagName(NotificationContentTxt);
foreach(列表中的System.Xml.XmlNode)
{
MessageBox.Show(n.InnerText);
}


HI guys im stuck and need some help

I need to get the value of the Node "NotificationContentTxt" from the XML below

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2014 rel. 2 (http://www.altova.com)-->
<n1:FATCAFileErrorNotification xmlns="urn:fatca:fatcanotificationbase" xmlns:n1="urn:fatca:fatcafileerrornotification" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
    <FATCANotificationHeaderGrp>
        <FATCANotificationCreateTs>2014-11-14T00:00:00Z</FATCANotificationCreateTs>
        <FATCANotificationRefId>Notif12345</FATCANotificationRefId>
        <FATCANotificationCd>NDC</FATCANotificationCd>
        <FATCAEntitySenderId>000000.00000.TA.840</FATCAEntitySenderId>
        <FATCAEntityReceiverId>S519K4.99999.SL.392</FATCAEntityReceiverId>
        <CopiedToFATCAEntityId>000000.00000.TA.392</CopiedToFATCAEntityId>
        <ContactInformationTxt>http://www.irs.gov/Businesses/Corporations/FATCA-Error-Notifications</ContactInformationTxt>
    </FATCANotificationHeaderGrp>
    <OriginalFileMetadataGrp>
        <IDESTransmissionId>a7c6363de36f4c2192856b4d3283747c</IDESTransmissionId>
        <IDESSendingTs>2014-11-10T00:00:00Z</IDESSendingTs>
        <OriginalIDESTransmissionId>c646151fe7ed4bd696efc8efe49226ac</OriginalIDESTransmissionId>
        <SenderFileId>SenderFile1</SenderFileId>
        <UncompressedFileSizeKBQty>100000</UncompressedFileSizeKBQty>
    </OriginalFileMetadataGrp>
    <NotificationContentTxt>The referenced file failed decryption by the IRS.  Please reference the action requested for the file.</NotificationContentTxt>
    <ActionRequestedGrp>
        <ActionRequestedTxt>Resubmit file.</ActionRequestedTxt>
        <ActionRequestedDueDateTxt>Your organization’s due date for filing Form 8966.</ActionRequestedDueDateTxt>
    </ActionRequestedGrp>
    
</n1:FATCAFileErrorNotification>


I keep getting a build error, my C# code is Below

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;


namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            
           OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "XML|*.xml";
            if ( ofd.ShowDialog() == DialogResult.OK)
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(ofd.FileName);
                MessageBox.Show(xDoc.SelectSingleNode("FATCAFileErrorNotification/NotificationContentTxt").InnerText);
            }
        }

    }
}


Thanks In Advance

解决方案

Try this:

System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
xml.Load(@"dirve:\path\file.xml");
System.Xml.XmlElement root = xml.DocumentElement;
System.Xml.XmlNodeList list = root.GetElementsByTagName("NotificationContentTxt");
foreach (System.Xml.XmlNode n in list)
{
    MessageBox.Show(n.InnerText);
}


这篇关于将XMl节点值显示到消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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