5 Replies - 4349 Views - Last Post: 11 November 2008 - 03:10 PM Rate Topic: -----

#1 richard123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-November 08

generate a document with xml and validate the xml file

Post icon  Posted 11 November 2008 - 09:09 AM

Hi everyone,
I am developing an application in c# that takes input and generate xml file and displays as a document at the ouput. I wrote a class and properties to pass the parameters from the class to generate the xml file. The sample code I wrote as follows:


serialXml.cs file

using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace sampleXml
{
   
	[XmlRoot("ClinicalDocument")]
 
	public class Patient
	{

		public Patient()
		{

			//default constructor

		}
	   
  private String firstName;

  private String lastName;

  private String gender;

  private String dateOfBirth;

  private String providerOrgName;

  private String assignedAuthorFirstName;

  private String assignedAuthorLastName;

  private String representOrgName;

  private String custodianOrgName;

  

  public String FirstName
  {

	  get
	  {

		  return firstName;

	  }

	  set
	  {

		  firstName = value;

	  }

  }



  public String LastName
  {

	  get
	  {

		  return lastName;

	  }

	  set
	  {

		  lastName = value;

	  }

  }

  public String Gender
  {

	  get
	  {

		  return gender;

	  }

	  set
	  {

		  gender = value;

	  }

  }



  public String DateOfBirth
  {

	  get
	  {

		  return dateOfBirth;

	  }

	  set
	  {

		  dateOfBirth = value;

	  }

  }



  public String ProviderOrgName
  {

	  get
	  {

		  return providerOrgName;

	  }

	  set
	  {

		  providerOrgName = value;

	  }

  }



  public String AssignedAuthorFirstName
  {

	  get
	  {

		  return assignedAuthorFirstName;

	  }

	  set
	  {

		  assignedAuthorFirstName = value;

	  }

  }



  public String AssignedAuthorLastName
  {

	  get
	  {

		  return assignedAuthorLastName;

	  }

	  set
	  {

		  assignedAuthorLastName = value;

	  }

  }

  public String RepresentOrgName
  {

	  get
	  {

		  return representOrgName;

	  }

	  set
	  {

		  representOrgName = value;

	  }

  }

  public String CustodianOrgName
  {

	  get
	  {

		  return custodianOrgName;

	  }

	  set
	  {

		  custodianOrgName = value;

	  }

  }

	 }
}

Codebind file code:

using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

namespace sampleXml
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
		  
			WriteXML();
			string strFile = @"c:\list.xml";
			outputBox.Text= GetXmlString(strFile);
			  
		}

	   void WriteXML()
		{
	 //let's try to save the XML document in a file: C:\pavel.xml
   try
   {
	   Patient patientObj = new Patient();
	  
	   patientObj.FirstName = "Naresh";
	   patientObj.LastName = "Valluri";
	   patientObj.DateOfBirth = "01/01/2000";
	   patientObj.ProviderOrgName = "Comdyn";
	   patientObj.AssignedAuthorFirstName = "northFirst";
	   patientObj.AssignedAuthorLastName = "northLast";
	   patientObj.RepresentOrgName = "charlotteOrg";
	   patientObj.CustodianOrgName = "devlopCust";

  // Serialization
	XmlSerializer s = new XmlSerializer(typeof(Patient));
	TextWriter w = new StreamWriter(@"c:\list.xml");

	s.Serialize(w, patientObj);
	w.Close();
	string strFilename = @"c:\list.xml";
	XmlDocument xmlDoc = new XmlDocument();

	if (File.Exists(strFilename))
	{
		xmlDoc.Load(strFilename);

		XmlElement elmRoot = xmlDoc.DocumentElement;
		XmlElement elmNew = xmlDoc.CreateElement("typeId");
		XmlAttribute NodeAtt = xmlDoc.CreateAttribute("root");
			NodeAtt.Value = "2.16.840.1.113883.1.3";
			elmNew.SetAttributeNode(NodeAtt);
			XmlAttribute NodeAtt1 = xmlDoc.CreateAttribute("extension");
			NodeAtt1.Value = "POCD_HD000040";
			elmNew.SetAttributeNode(NodeAtt1);
		elmRoot.AppendChild(elmNew);
		xmlDoc.Save(strFilename);

		XmlDocument myXmlDocument = new XmlDocument();
		myXmldocument.Load(@"c:\list.xml");
		XmlElement elem1;
		elem1 = myXmldocument.DocumentElement;

			  if (elem1.Name == "ClinicalDocument")
				{
					XmlAttribute RootAtt3 = myXmldocument.CreateAttribute("xsi:schemaLocation");
					RootAtt3.Value = "urn:h17-org:v3 CDA.xsd";
					elem1.SetAttributeNode(RootAtt3);
					myXmldocument.AppendChild(elem1);
				}

		myXmldocument.Save(@"c:\list.xml");

					  // Open the Makes.xml file
			XmlDocument docXMLFile = new XmlDocument();
			docXMLFile.Load(@"c:\list.xml");

			// Get the root node so we can explore its children
			XmlElement nodRoot = docXMLFile.DocumentElement;
			// Store all the values of the elements in a string
			string allMyChildren = nodRoot.InnerText;
		
		  Response.Write(allMyChildren);
		   
 
	}


	// Deserialization
	//serialXml newList;
	//TextReader r = new StreamReader(@"c:\list.xml");
	//newList = (serialXml)s.Deserialize®;
	//Response.Write(newList.Items[0].name.ToString());
	//Response.Write("\n");
	//Response.Write("\n");
	//Response.Write(newList.Items[0].price.ToString());
	//r.Close();
   }
   catch (Exception e)
   {
	Console.WriteLine(e.Message);
   }
   Console.ReadLine();

		}

		void WriteError(string str)
		{
			outputBox.Text = str;
		}

		static string GetXmlString(string strFile)
		{
			// Load the xml file into XmlDocument object.
			XmlDocument xmlDoc = new XmlDocument();
			try
			{
				xmlDoc.Load(strFile);
			}
			catch (XmlException e)
			{
				Console.WriteLine(e.Message);
			}
			// Now create StringWriter object to get data from xml document.
			StringWriter sw = new StringWriter();
			XmlTextWriter xw = new XmlTextWriter(sw);
			xmlDoc.WriteTo(xw);
			return sw.ToString();
		}	


	}
}


Now my problem is I need to validate the generated xml file using some xsd file and display the xml file as document in the output window.

Please anyone help me regarding this issue..

Thanks in advance...

Is This A Good Question/Topic? 0
  • +

Replies To: generate a document with xml and validate the xml file

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: generate a document with xml and validate the xml file

Posted 11 November 2008 - 09:41 AM

You might try the following links for some guidance on validating XML using XSD. It is pretty straight forward, but if you have any questions you know where we are.

How To Validate an XML Document
Validation of XML with XSD
Was This Post Helpful? 0
  • +
  • -

#3 mark.leonard  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-October 08

Re: generate a document with xml and validate the xml file

Posted 11 November 2008 - 09:58 AM

View Postrichard123, on 11 Nov, 2008 - 08:09 AM, said:

Hi everyone,
I am developing an application in c# that takes input and generate xml file and displays as a document at the ouput. I wrote a class and properties to pass the parameters from the class to generate the xml file. The sample code I wrote as follows:


serialXml.cs file

using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace sampleXml
{
   
	[XmlRoot("ClinicalDocument")]
 
	public class Patient
	{

		public Patient()
		{

			//default constructor

		}
	   
  private String firstName;

  private String lastName;

  private String gender;

  private String dateOfBirth;

  private String providerOrgName;

  private String assignedAuthorFirstName;

  private String assignedAuthorLastName;

  private String representOrgName;

  private String custodianOrgName;

  

  public String FirstName
  {

	  get
	  {

		  return firstName;

	  }

	  set
	  {

		  firstName = value;

	  }

  }



  public String LastName
  {

	  get
	  {

		  return lastName;

	  }

	  set
	  {

		  lastName = value;

	  }

  }

  public String Gender
  {

	  get
	  {

		  return gender;

	  }

	  set
	  {

		  gender = value;

	  }

  }



  public String DateOfBirth
  {

	  get
	  {

		  return dateOfBirth;

	  }

	  set
	  {

		  dateOfBirth = value;

	  }

  }



  public String ProviderOrgName
  {

	  get
	  {

		  return providerOrgName;

	  }

	  set
	  {

		  providerOrgName = value;

	  }

  }



  public String AssignedAuthorFirstName
  {

	  get
	  {

		  return assignedAuthorFirstName;

	  }

	  set
	  {

		  assignedAuthorFirstName = value;

	  }

  }



  public String AssignedAuthorLastName
  {

	  get
	  {

		  return assignedAuthorLastName;

	  }

	  set
	  {

		  assignedAuthorLastName = value;

	  }

  }

  public String RepresentOrgName
  {

	  get
	  {

		  return representOrgName;

	  }

	  set
	  {

		  representOrgName = value;

	  }

  }

  public String CustodianOrgName
  {

	  get
	  {

		  return custodianOrgName;

	  }

	  set
	  {

		  custodianOrgName = value;

	  }

  }

	 }
}

Codebind file code:

using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

namespace sampleXml
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
		  
			WriteXML();
			string strFile = @"c:\list.xml";
			outputBox.Text= GetXmlString(strFile);
			  
		}

	   void WriteXML()
		{
	 //let's try to save the XML document in a file: C:\pavel.xml
   try
   {
	   Patient patientObj = new Patient();
	  
	   patientObj.FirstName = "Naresh";
	   patientObj.LastName = "Valluri";
	   patientObj.DateOfBirth = "01/01/2000";
	   patientObj.ProviderOrgName = "Comdyn";
	   patientObj.AssignedAuthorFirstName = "northFirst";
	   patientObj.AssignedAuthorLastName = "northLast";
	   patientObj.RepresentOrgName = "charlotteOrg";
	   patientObj.CustodianOrgName = "devlopCust";

  // Serialization
	XmlSerializer s = new XmlSerializer(typeof(Patient));
	TextWriter w = new StreamWriter(@"c:\list.xml");

	s.Serialize(w, patientObj);
	w.Close();
	string strFilename = @"c:\list.xml";
	XmlDocument xmlDoc = new XmlDocument();

	if (File.Exists(strFilename))
	{
		xmlDoc.Load(strFilename);

		XmlElement elmRoot = xmlDoc.DocumentElement;
		XmlElement elmNew = xmlDoc.CreateElement("typeId");
		XmlAttribute NodeAtt = xmlDoc.CreateAttribute("root");
			NodeAtt.Value = "2.16.840.1.113883.1.3";
			elmNew.SetAttributeNode(NodeAtt);
			XmlAttribute NodeAtt1 = xmlDoc.CreateAttribute("extension");
			NodeAtt1.Value = "POCD_HD000040";
			elmNew.SetAttributeNode(NodeAtt1);
		elmRoot.AppendChild(elmNew);
		xmlDoc.Save(strFilename);

		XmlDocument myXmlDocument = new XmlDocument();
		myXmldocument.Load(@"c:\list.xml");
		XmlElement elem1;
		elem1 = myXmldocument.DocumentElement;

			  if (elem1.Name == "ClinicalDocument")
				{
					XmlAttribute RootAtt3 = myXmldocument.CreateAttribute("xsi:schemaLocation");
					RootAtt3.Value = "urn:h17-org:v3 CDA.xsd";
					elem1.SetAttributeNode(RootAtt3);
					myXmldocument.AppendChild(elem1);
				}

		myXmldocument.Save(@"c:\list.xml");

					  // Open the Makes.xml file
			XmlDocument docXMLFile = new XmlDocument();
			docXMLFile.Load(@"c:\list.xml");

			// Get the root node so we can explore its children
			XmlElement nodRoot = docXMLFile.DocumentElement;
			// Store all the values of the elements in a string
			string allMyChildren = nodRoot.InnerText;
		
		  Response.Write(allMyChildren);
		   
 
	}


	// Deserialization
	//serialXml newList;
	//TextReader r = new StreamReader(@"c:\list.xml");
	//newList = (serialXml)s.Deserialize®;
	//Response.Write(newList.Items[0].name.ToString());
	//Response.Write("\n");
	//Response.Write("\n");
	//Response.Write(newList.Items[0].price.ToString());
	//r.Close();
   }
   catch (Exception e)
   {
	Console.WriteLine(e.Message);
   }
   Console.ReadLine();

		}

		void WriteError(string str)
		{
			outputBox.Text = str;
		}

		static string GetXmlString(string strFile)
		{
			// Load the xml file into XmlDocument object.
			XmlDocument xmlDoc = new XmlDocument();
			try
			{
				xmlDoc.Load(strFile);
			}
			catch (XmlException e)
			{
				Console.WriteLine(e.Message);
			}
			// Now create StringWriter object to get data from xml document.
			StringWriter sw = new StringWriter();
			XmlTextWriter xw = new XmlTextWriter(sw);
			xmlDoc.WriteTo(xw);
			return sw.ToString();
		}	


	}
}


Now my problem is I need to validate the generated xml file using some xsd file and display the xml file as document in the output window.

Please anyone help me regarding this issue..

Thanks in advance...


I just had a quick skim over your code - but I am not sure I can pick out where you are trying to do the validation, have you tried to implement this?

I am not sure what you mean by "display the xml file as document in the output window" can you clarify?
Was This Post Helpful? 0
  • +
  • -

#4 richard123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-November 08

Re: generate a document with xml and validate the xml file

Posted 11 November 2008 - 11:25 AM

View Postmark.leonard, on 11 Nov, 2008 - 08:58 AM, said:

View Postrichard123, on 11 Nov, 2008 - 08:09 AM, said:

Hi everyone,
I am developing an application in c# that takes input and generate xml file and displays as a document at the ouput. I wrote a class and properties to pass the parameters from the class to generate the xml file. The sample code I wrote as follows:


serialXml.cs file

using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace sampleXml
{
   
	[XmlRoot("ClinicalDocument")]
 
	public class Patient
	{

		public Patient()
		{

			//default constructor

		}
	   
  private String firstName;

  private String lastName;

  private String gender;

  private String dateOfBirth;

  private String providerOrgName;

  private String assignedAuthorFirstName;

  private String assignedAuthorLastName;

  private String representOrgName;

  private String custodianOrgName;

  

  public String FirstName
  {

	  get
	  {

		  return firstName;

	  }

	  set
	  {

		  firstName = value;

	  }

  }



  public String LastName
  {

	  get
	  {

		  return lastName;

	  }

	  set
	  {

		  lastName = value;

	  }

  }

  public String Gender
  {

	  get
	  {

		  return gender;

	  }

	  set
	  {

		  gender = value;

	  }

  }



  public String DateOfBirth
  {

	  get
	  {

		  return dateOfBirth;

	  }

	  set
	  {

		  dateOfBirth = value;

	  }

  }



  public String ProviderOrgName
  {

	  get
	  {

		  return providerOrgName;

	  }

	  set
	  {

		  providerOrgName = value;

	  }

  }



  public String AssignedAuthorFirstName
  {

	  get
	  {

		  return assignedAuthorFirstName;

	  }

	  set
	  {

		  assignedAuthorFirstName = value;

	  }

  }



  public String AssignedAuthorLastName
  {

	  get
	  {

		  return assignedAuthorLastName;

	  }

	  set
	  {

		  assignedAuthorLastName = value;

	  }

  }

  public String RepresentOrgName
  {

	  get
	  {

		  return representOrgName;

	  }

	  set
	  {

		  representOrgName = value;

	  }

  }

  public String CustodianOrgName
  {

	  get
	  {

		  return custodianOrgName;

	  }

	  set
	  {

		  custodianOrgName = value;

	  }

  }

	 }
}

Codebind file code:

using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

namespace sampleXml
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
		  
			WriteXML();
			string strFile = @"c:\list.xml";
			outputBox.Text= GetXmlString(strFile);
			  
		}

	   void WriteXML()
		{
	 //let's try to save the XML document in a file: C:\pavel.xml
   try
   {
	   Patient patientObj = new Patient();
	  
	   patientObj.FirstName = "Naresh";
	   patientObj.LastName = "Valluri";
	   patientObj.DateOfBirth = "01/01/2000";
	   patientObj.ProviderOrgName = "Comdyn";
	   patientObj.AssignedAuthorFirstName = "northFirst";
	   patientObj.AssignedAuthorLastName = "northLast";
	   patientObj.RepresentOrgName = "charlotteOrg";
	   patientObj.CustodianOrgName = "devlopCust";

  // Serialization
	XmlSerializer s = new XmlSerializer(typeof(Patient));
	TextWriter w = new StreamWriter(@"c:\list.xml");

	s.Serialize(w, patientObj);
	w.Close();
	string strFilename = @"c:\list.xml";
	XmlDocument xmlDoc = new XmlDocument();

	if (File.Exists(strFilename))
	{
		xmlDoc.Load(strFilename);

		XmlElement elmRoot = xmlDoc.DocumentElement;
		XmlElement elmNew = xmlDoc.CreateElement("typeId");
		XmlAttribute NodeAtt = xmlDoc.CreateAttribute("root");
			NodeAtt.Value = "2.16.840.1.113883.1.3";
			elmNew.SetAttributeNode(NodeAtt);
			XmlAttribute NodeAtt1 = xmlDoc.CreateAttribute("extension");
			NodeAtt1.Value = "POCD_HD000040";
			elmNew.SetAttributeNode(NodeAtt1);
		elmRoot.AppendChild(elmNew);
		xmlDoc.Save(strFilename);

		XmlDocument myXmlDocument = new XmlDocument();
		myXmldocument.Load(@"c:\list.xml");
		XmlElement elem1;
		elem1 = myXmldocument.DocumentElement;

			  if (elem1.Name == "ClinicalDocument")
				{
					XmlAttribute RootAtt3 = myXmldocument.CreateAttribute("xsi:schemaLocation");
					RootAtt3.Value = "urn:h17-org:v3 CDA.xsd";
					elem1.SetAttributeNode(RootAtt3);
					myXmldocument.AppendChild(elem1);
				}

		myXmldocument.Save(@"c:\list.xml");

					  // Open the Makes.xml file
			XmlDocument docXMLFile = new XmlDocument();
			docXMLFile.Load(@"c:\list.xml");

			// Get the root node so we can explore its children
			XmlElement nodRoot = docXMLFile.DocumentElement;
			// Store all the values of the elements in a string
			string allMyChildren = nodRoot.InnerText;
		
		  Response.Write(allMyChildren);
		   
 
	}


	// Deserialization
	//serialXml newList;
	//TextReader r = new StreamReader(@"c:\list.xml");
	//newList = (serialXml)s.Deserialize®;
	//Response.Write(newList.Items[0].name.ToString());
	//Response.Write("\n");
	//Response.Write("\n");
	//Response.Write(newList.Items[0].price.ToString());
	//r.Close();
   }
   catch (Exception e)
   {
	Console.WriteLine(e.Message);
   }
   Console.ReadLine();

		}

		void WriteError(string str)
		{
			outputBox.Text = str;
		}

		static string GetXmlString(string strFile)
		{
			// Load the xml file into XmlDocument object.
			XmlDocument xmlDoc = new XmlDocument();
			try
			{
				xmlDoc.Load(strFile);
			}
			catch (XmlException e)
			{
				Console.WriteLine(e.Message);
			}
			// Now create StringWriter object to get data from xml document.
			StringWriter sw = new StringWriter();
			XmlTextWriter xw = new XmlTextWriter(sw);
			xmlDoc.WriteTo(xw);
			return sw.ToString();
		}	


	}
}


Now my problem is I need to validate the generated xml file using some xsd file and display the xml file as document in the output window.

Please anyone help me regarding this issue..

Thanks in advance...


I just had a quick skim over your code - but I am not sure I can pick out where you are trying to do the validation, have you tried to implement this?

I am not sure what you mean by "display the xml file as document in the output window" can you clarify?


Thanks a lot for giving reply. Actually, what I was trying to create and store xml documents (CDA format) using the transcription information. CDA means Clinical Document Architecture. I never worked on HL7 - CDA format. I got some material regarding CDA as below.

http://www.hl7.org/d...lic/faq/cda.cfm

http://www.alschuler...ck-start-guides

I went through those links. But I didn't find any way for how to implement
the CDA. So first I tried as above to generate xml files using input. And I need to validate those generated xml files using xsd. Finally I need to display the xml file as document without any tags. Sorry for my poor english. Hope you 'll understand.

Thanks in advance
Was This Post Helpful? 0
  • +
  • -

#5 richard123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 11-November 08

Re: generate a document with xml and validate the xml file

Posted 11 November 2008 - 02:54 PM

still looking for help on this................
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: generate a document with xml and validate the xml file

Posted 11 November 2008 - 03:10 PM

Did you read the two links I posted previously on validating an XML file?

What else, specifically, do you need help with?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1