0

I want to create 1095 e-file xml using c# code. For that i want to create dynamic tags that means if data is available then only creating tags otherwise it can not show that tag.

Shaik
  • 1
  • Check out [this](https://stackoverflow.com/questions/284324/how-can-i-build-xml-in-c) – Prashant Pimpale Dec 24 '18 at 04:50
  • 3
    Hi, welcome to stack overflow. Please refer the [ask] link for more details on how to ask a question and update your question accordingly. – Jeroen Heier Dec 24 '18 at 04:54
  • What is a **1095 e-file**? It is this: http://www.efile1095.com/ ? How does the XML look like? There are many of us that are not from USA and the **e-file** is unknown to us. And how are you data stored? What is your code? Should it be only a web based question/answer/fill details page? What have you done so far? There are may thinks that are not addressed in your post. But unfortunately without knowing (much) more details we are unable to help you in any way. Please update your question and add the specific details. – Julo Dec 24 '18 at 05:08
  • 1095 e file is a Employer providing Employees Health insurance Coverage to IRS.For that i want to create xml file like below for multiple employees in a single file. – Shaik Dec 24 '18 at 05:20
  • I need file like a below - Comp Name BUSINESS_TIN 899090900 - First Name Person Last Name Person 9090909000 – Shaik Dec 24 '18 at 05:26

1 Answers1

0

Here is sample of using xml linq to create your xml file. You can add IF statements as necessary to skip adding any elements

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><root xmlns:irs=\"myUrl\"></root>";

            XDocument doc = XDocument.Parse(header);
            XElement root = doc.Root;
            XNamespace irs = root.GetNamespaceOfPrefix("irs");

            XElement businessName = new XElement("BusinessNameLine1Txt", "Comp Name");
            root.Add(businessName);

            XElement tinRequest = new XElement(irs + "TINRequestTypeCd");
            root.Add(tinRequest);

            XElement employerEIN = new XElement(irs + "EmployerEIN", "899090900");
            root.Add(employerEIN);

            XElement contactNameGrp = new XElement("ContactNameGrp");
            root.Add(contactNameGrp);

            XElement firstName = new XElement("PersonFirstNm", "First Name Person");
            contactNameGrp.Add(firstName);

            XElement lastName = new XElement("PersonLastNm", "Last Name Person");
            contactNameGrp.Add(lastName);
        }
    }
}
//sample output
//<?xml version="1.0" encoding="utf-8" ?>
//<root xmlns:irs="myUrl">
//<BusinessName>
//  <BusinessNameLine1Txt>Comp Name</BusinessNameLine1Txt>
//</BusinessName> 
//<irs:TINRequestTypeCd>BUSINESS_TIN</irs:TINRequestTypeCd> 
//<irs:EmployerEIN>899090900</irs:EmployerEIN> 
//<ContactNameGrp>
//  <PersonFirstNm>First Name Person</PersonFirstNm>
//  <PersonLastNm>Last Name Person</PersonLastNm>
//</ContactNameGrp> <ContactPhoneNum>9090909000</ContactPhoneNum>
//</root>
jdweng
  • 33,250
  • 2
  • 15
  • 20