Click here to Skip to main content
15,900,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI guys im stuck and need some help

I need to get the value of the Node "NotificationContentTxt" from the XML below
XML
<?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
C#
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
Posted
Updated 22-Mar-15 2:40am
v2
Comments
Kornfeld Eliyahu Peter 22-Mar-15 8:41am    
What error? On which line?

1 solution

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);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900