XML

1. What is Extensible Markup Language (XML).

XML is a simple and flexible markup language in the text format. Nowadays, it is widely used to exchange a large variety of data over the Internet. XML consists of data as text in well-defined customized layouts by using self-defining tags. These user-defined tags are user friendly because they contain the name given by the user and make the information easily understandable to a user. These user-friendly features made XML to be widely used as a standard data-interchange format. The World Wide Web Consortium (W3C) frequently develops new standard for XML usage by different software vendors and solution providers. XML plays a very significant role with respect to .NET Framework 4.0. .NET Framework 4.0 provides us with a namespace called System.Xml, which includes classes that are used to work with XML.


2. Explain the difference between XML and HTML.

  • XML describes data while HTML describes how the data should be displayed. Therefore, HTML is about displaying information while XML is about describing information.
  • XML supports user-defined tags while HTML provides pre-defined tags.
  • XML is a case-sensitive language while HTML language is not case-sensitive.
  • In XML, all tags must be closed; while in HTML, it is not necessary to close each tag.

 3. How to create XML?
protected void btngeneratexml_Click(object sender, EventArgs e)
    {
        try
        {
            int Encounter;
            if (GridView1.Rows.Count != 0)
            {
                StringBuilder strBuilder = new StringBuilder();
                DataSet ds = new DataSet();
                Label Lbl_InsCompIDVal = (Label)GridView1.Rows[0].FindControl("Lbl_InsCompID");
                Label Lbl_lbXMLInsurerComID = (Label)GridView1.Rows[0].FindControl("lbXMLInsurerComID");
                Label Lbl_lblInsCompName = (Label)GridView1.Rows[0].FindControl("Lbl_Salary");
                Label Lbl_TPAName1 = (Label)GridView1.Rows[0].FindControl("Lbl_TPAName1");
                PrefiXmlName = PrefiXmlName + Lbl_lblInsCompName.Text.Substring(0, 3);
                if (Lbl_lbXMLInsurerComID.Text != "0")
                {
                    HdnInsComID.Value = Lbl_lbXMLInsurerComID.Text;
                }
                else
                {
                    HdnInsComID.Value = Lbl_InsCompIDVal.Text;
                }
                xmlFileName = BatchText.ToString() + "_" + DateTime.Now.ToString("dd-MMM-yyyy");
                xmlFileName = PrefiXmlName + xmlFileName + ".xml";            
                char rowSep = ',';
                string strBillNumber = getEncounter();
                string[] Text = strBillNumber.Split(rowSep);
                Encounter = Text.Length;
                if (Text.Length > 0)
                {
                    string xmlpath = Server.MapPath("~/" + "EClaim_XML" + "/" + xmlFileName);
                    //clsObjGenerateClaim.insert_record(clsObjCommon.GetDateForDB(txtFromDate.Text), clsObjCommon.GetDateForDB(txtToDate.Text), txtID.Text, txtPlan.Text, txtClaimName.Text, xmlFileName, Encounter, Convert.ToString(Session["GetProviderID"]), Convert.ToInt16(Session["UserID"]), Convert.ToInt16(Session["UserID"]), "INSERT");
                    clsObjGenerateClaim.insert_record(clsObjCommon.GetDateForDB(txtFromDate.Text), clsObjCommon.GetDateForDB(txtToDate.Text), Ddl_AgencyName.SelectedValue.ToString().TrimEnd(), "TestPlan", "Test", xmlFileName, Encounter, Convert.ToString(Session["GetProviderID"]), Convert.ToInt16(Session["UserID"]), Convert.ToInt16(Session["UserID"]), "INSERT", xmlpath);
                    strBuilder.Append("<?xml version='1.0' encoding='utf-8' ?>");
                   strBuilder.Append("<Claim.Submission xmlns:tns=\"xxxxxxxxxxxxx">".ToString());
                 
                    strBuilder.Append("<Header>");
                    strBuilder.Append("<SenderID>" + lblProviderID.Text + "</SenderID>");
                    //strBuilder.Append("<ReceiverID>" + txtID.Text.TrimEnd() + "</ReceiverID>");
                    strBuilder.Append("<ReceiverID>" + HdnInsComID.Value + "</ReceiverID>");
                    strBuilder.Append("<TransactionDate>" + DateTime.Now.ToString("dd/MM/yyyy") + " " + DateTime.Now.ToString("H:mm") + "</TransactionDate>");
                    strBuilder.Append("<RecordCount>" + count.ToString() + "</RecordCount>");
                    strBuilder.Append("<DispositionFlag>" + Convert.ToString(ddlDispositionFlag.SelectedItem.Text.Trim()) + "</DispositionFlag>");
                    strBuilder.Append("</Header>");
                    for (int cont = 0; cont < Text.Length; cont++)
                    {
                        ds = clsObjGenerateClaim.GenerateXML(Text[cont].ToString(), "TESTCLAIM");
                        for (int a = 0; a < ds.Tables[0].Rows.Count; a++)
                        {
                            string str = "";
                            str = ds.Tables[0].Rows[a]["xmlValue"].ToString();
                            str = str.Replace("<Clinician/>", "<Clinician></Clinician>");
                            str = str.Replace("<Clinician />", "<Clinician></Clinician>");
                            str = str.Replace("<PriorAuthorizationID/>", "<PriorAuthorizationID></PriorAuthorizationID>");
                            str = str.Replace("<PriorAuthorizationID />", "<PriorAuthorizationID></PriorAuthorizationID>");
                            str = str.Replace("<PackageName/>", "<PackageName></PackageName>");
                            str = str.Replace("<PackageName />", "<PackageName></PackageName>");
                            strBuilder.Append(str);
                            //strBuilder.Append(ds.Tables[0].Rows[a]["xmlValue"].ToString());
                        }
                        ds.Dispose();
                    }
                 
                    strBuilder.Append("</Claim.Submission>");
                    FileStream fStream = File.Create(Server.MapPath("~/" + "EClaim_XML" + "/" + xmlFileName));                  
                    fStream.Close();
                    StreamWriter sWriter = new StreamWriter(Server.MapPath("~/" + "EClaim_XML" + "/" + xmlFileName));
                    sWriter.Write(strBuilder);
                    sWriter.Close();
                }
            }
         
       }
        catch (Exception ex)
        { }
    }




4. How to post XML to the post office?
if (System.IO.File.Exists(Server.MapPath(@PathName)))
                        {
                            FileStream fs1 = new FileStream(Server.MapPath(@PathName), FileMode.Open, System.IO.FileAccess.Read);
                            BinaryReader br1 = new BinaryReader(fs1);
                            byte[] imgbyte1 = new byte[fs1.Length + 1];
                            imgbyte1 = br1.ReadBytes(Convert.ToInt32((fs1.Length)));
                            byte[] imgbyte = new byte[2000];
                            string a = "";                        
                            Webservices objUTR = new Webservices();
                            objUTR.UploadTransaction("UserID", "Password", imgbyte1, lblXmlFileName.Text, out a, out imgbyte);
                            if (imgbyte != null)
                            {
                                string s1 = Encoding.UTF8.GetString(imgbyte);
                                string Ss = ASCIIEncoding.ASCII.GetString(imgbyte);

                                StringBuilder hex = new StringBuilder(imgbyte.Length * 2);
                                foreach (int b in imgbyte)
                                    hex.AppendFormat("{0:x2}", b);
                                string s2= hex.ToString();
                                string sGenName = "SubmissionError";
                                using (System.IO.StreamWriter SW = new System.IO.StreamWriter(
                                       Server.MapPath("~/" + "Eclaim_XMLError" + "/" + sGenName)))
                                {
                                    SW.WriteLine(s1);
                                    SW.Close();
                                }
                                System.IO.FileStream fs = null;
                                fs = System.IO.File.Open(Server.MapPath("~/" + "Eclaim_XMLError" + "/" +
                                         sGenName + ".txt"), System.IO.FileMode.Open);
                                byte[] btFile = new byte[fs.Length];
                                fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
                                fs.Close();
                                Response.AddHeader("Content-disposition", "attachment; filename=" + sGenName);
                                Response.ContentType = "application/octet-stream";
                                Response.BinaryWrite(btFile);
                                Response.End();
                            }
                            if (a != null)
                            {
                                lblShowMsg.Visible = true;
                                lblShowMsg.Text = a;
                                if (a == "Operation is successful")
                                {
lblShowMsg.Visible = true;
                                lblShowMsg.Text = "Operation is successful";
                                }
                            }
                        }


5. How to Read XML and save in to the database?

First select the XML file using of file uploader then called this function:-

public void ReadXML()
    {
        lstHeader.Clear();
        lstClaim.Clear();
        lstEncounter.Clear();
        lstActivity.Clear();
        grdViewCustomers.DataSource = "";
        grdViewCustomers.DataBind();
        DataSet ds=new DataSet();
        string xmlFileName = FileUpload1.FileName;

        string xmlpath = Server.MapPath("~/" + "EClaim_XML" + "/" + xmlFileName);
        XmlTextReader xmlreader = new XmlTextReader(xmlpath);
        ds.ReadXml(xmlreader);
if (ds.Tables["Header"] != null)
{
    for (int i = 0; i < ds.Tables["Header"].Rows.Count; i++)
    {
        lstHeader.Add(new clsBillDetail
        {
            SenderID = ds.Tables["Header"].Rows[i]["SenderID"].ToString(),
            ReceiverID = ds.Tables["Header"].Rows[i]["ReceiverID"].ToString(),
            TransactionDate = ds.Tables["Header"].Rows[i]["TransactionDate"].ToString(),
            RecordCount = ds.Tables["Header"].Rows[i]["RecordCount"].ToString(),
            DispositionFlag = ds.Tables["Header"].Rows[i]["DispositionFlag"].ToString()          
        });      
    }
}

if (ds.Tables["Claim"] != null)
{
    for (int i = 0; i < ds.Tables["Claim"].Rows.Count; i++)
    {
        lstClaim.Add(new clsBillDetail
        {
            ID = ds.Tables["Claim"].Rows[i]["ID"].ToString(),
            IDPayer = ds.Tables["Claim"].Rows[i]["IDPayer"].ToString(),
            ProviderID = ds.Tables["Claim"].Rows[i]["ProviderID"].ToString(),
            PaymentReference = ds.Tables["Claim"].Rows[i]["PaymentReference"].ToString(),
            DateSettlement = ds.Tables["Claim"].Rows[i]["DateSettlement"].ToString(),
            Claim_Id = ds.Tables["Claim"].Rows[i]["Claim_Id"].ToString()
        });
    }


}
if (ds.Tables["Encounter"] != null)
{
    for (int i = 0; i < ds.Tables["Encounter"].Rows.Count; i++)
    {
        lstEncounter.Add(new clsBillDetail
        {
            FacilityID = ds.Tables["Encounter"].Rows[i]["FacilityID"].ToString(),
            Claim_Id = ds.Tables["Encounter"].Rows[i]["Claim_Id"].ToString()
        });
    }
}

if (ds.Tables["Activity"] != null)
{
    for (int i = 0; i < ds.Tables["Activity"].Rows.Count; i++)
    {
        DataColumnCollection columns = ds.Tables["Activity"].Columns;
        if (columns.Contains("DenialCode"))
        {
            lstActivity.Add(new clsBillDetail
            {
                ID = ds.Tables["Activity"].Rows[i]["ID"].ToString(),
                Start = ds.Tables["Activity"].Rows[i]["Start"].ToString(),
                Type = ds.Tables["Activity"].Rows[i]["Type"].ToString(),
                Code = ds.Tables["Activity"].Rows[i]["Code"].ToString(),
                Quantity = Convert.ToInt32(ds.Tables["Activity"].Rows[i]["Quantity"].ToString()),
                Net = ds.Tables["Activity"].Rows[i]["Net"].ToString(),
                Clinician = ds.Tables["Activity"].Rows[i]["Clinician"].ToString(),
                Gross = ds.Tables["Activity"].Rows[i]["Gross"].ToString(),
                PatientShare = ds.Tables["Activity"].Rows[i]["PatientShare"].ToString(),
                PaymentAmount = ds.Tables["Activity"].Rows[i]["PaymentAmount"].ToString(),
                DenialCode = ds.Tables["Activity"].Rows[i]["DenialCode"].ToString(),
                Claim_Id = ds.Tables["Activity"].Rows[i]["Claim_Id"].ToString()
            });
        }
        else
        {
            lstActivity.Add(new clsBillDetail
            {
                ID = ds.Tables["Activity"].Rows[i]["ID"].ToString(),
                Start = ds.Tables["Activity"].Rows[i]["Start"].ToString(),
                Type = ds.Tables["Activity"].Rows[i]["Type"].ToString(),
                Code = ds.Tables["Activity"].Rows[i]["Code"].ToString(),
                Quantity = Convert.ToInt32(ds.Tables["Activity"].Rows[i]["Quantity"].ToString()),
                Net = ds.Tables["Activity"].Rows[i]["Net"].ToString(),
                Clinician = ds.Tables["Activity"].Rows[i]["Clinician"].ToString(),
                Gross = ds.Tables["Activity"].Rows[i]["Gross"].ToString(),
                PatientShare = ds.Tables["Activity"].Rows[i]["PatientShare"].ToString(),
                PaymentAmount = ds.Tables["Activity"].Rows[i]["PaymentAmount"].ToString(),
                DenialCode = "",
                Claim_Id = ds.Tables["Activity"].Rows[i]["Claim_Id"].ToString()
            });
        }
    }
}

grdViewCustomers.DataSource = lstClaim;
grdViewCustomers.DataBind();

    }



No comments: