?
Solved

Trouble creating an xml file in C#

Posted on 2013-06-13
9
Medium Priority
?
359 Views
Last Modified: 2013-06-21
Hey guys!!

I'm having trouble creating an xml file in C#.

XmlTextWriter writer = new XmlTextWriter("C:\\test.xml", Encoding.UTF8);
            writer.WriteStartDocument();
            writer.WriteRaw("<Message xmlns="http://www.surescripts.com/messaging">");
            //I can't seem to make this work. Should be <Message xmlns="http://www.surescripts.com/messaging">

            writer.WriteStartElement("root");
            // I don't want to print Root in my document.
           
            writer.WriteStartElement("Header");
            writer.WriteElementString("To","mailto:4736190679001.spi@surescripts.com");
            writer.WriteElementString("From","mailto:1111111.ncpdp@surescripts.com");
            writer.WriteElementString("MessageID", "333c32da7169436fbc703153bd722d34");
            writer.WriteElementString("SentTime", "2006-06-23T21:19:04.9Z");
            writer.WriteEndElement();


            writer.WriteStartElement("Body");
            writer.WriteElementString("Refill Request", "");
            writer.WriteElementString("RxReferenceNumber", "FMEM-999512");
            writer.WriteElementString("PrescriberOrderNumber","ORD-888512");

            writer.WriteStartElement("Pharmacy");
            writer.WriteStartElement("Identification");
            writer.WriteElementString("StoreName", "C 4");
            writer.WriteEndElement();
            writer.WriteStartElement("Address");
            writer.WriteElementString("AddressLine1", "500 W Commercial St");
            writer.WriteElementString("City", "Ozark");
            writer.WriteElementString("State", "AR");
            writer.WriteElementString("ZipCode", "72949");
            writer.WriteEndElement();

            writer.WriteStartElement("PhoneNumbers");
            writer.WriteStartElement("Phone");
            writer.WriteElementString("Number", "4796672101");
            writer.WriteElementString("Qualifier", "TE");
            writer.WriteEndElement();
            writer.WriteStartElement("Phone");
            writer.WriteElementString("Number", "4796671605");
            writer.WriteElementString("Qualifier", "FX");
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteStartElement("Prescriber");
            writer.WriteStartElement("Identification");
            writer.WriteElementString("SPI", "580805988");
            writer.WriteEndElement();
            writer.WriteStartElement("Name");
            writer.WriteElementString("Last Name", "Mouse");
            writer.WriteElementString("First Name", "Mickey");
            writer.WriteElementString("Middle Name", "R.");
            writer.WriteElementString("Suffix", "M.D.");
            writer.WriteElementString("Prefix", "Dr.");
            writer.WriteEndElement();
            writer.WriteStartElement("Address");
            writer.WriteElementString("Address Line 1", "30 Hunter Lane");
            writer.WriteElementString("City", "Carbon City");
            writer.WriteElementString("State", "AR");
            writer.WriteElementString("ZipCode", "72955");
            writer.WriteEndElement();

            writer.WriteStartElement("PhoneNumbers");
            writer.WriteStartElement("Phone");
            writer.WriteElementString("Number", "4796672101");
            writer.WriteElementString("Qualifier", "TE");
            writer.WriteEndElement();
            writer.WriteStartElement("Phone");
            writer.WriteElementString("Number", "4796671605");
            writer.WriteElementString("Qualifier", "FX");
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteEndElement();
           
            writer.WriteStartElement("Patient");
            writer.WriteStartElement("Identification");
            writer.WriteElementString("SocialSecurity", "1234567890");
            writer.WriteEndElement();
            writer.WriteStartElement("Name");
            writer.WriteElementString("LastName", "Mouse");
            writer.WriteElementString("FirstName", "Minnie");
            writer.WriteElementString("MiddleName", "G.");
            writer.WriteEndElement();
            writer.WriteElementString("Gender", "F");
            writer.WriteElementString("DateOfBirth", "19350101");
            writer.WriteStartElement("Address");
            writer.WriteElementString("Address Line 1", "1922 N Carbon City Rd");
            writer.WriteElementString("City", "Carbon City");
            writer.WriteElementString("State", "AR");
            writer.WriteElementString("ZipCode", "72955");
            writer.WriteEndElement();
            writer.WriteStartElement("PhoneNumbers");
            writer.WriteStartElement("Phone");
            writer.WriteElementString("Number", "4796332101");
            writer.WriteElementString("Qualifier", "TE");
            writer.WriteEndElement();
            writer.WriteStartElement("Phone");
            writer.WriteElementString("Number", "4796331605");
            writer.WriteElementString("Qualifier", "FX");
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteEndElement();
           
            writer.WriteStartElement("Medication Prescribed");
            writer.WriteElementString("DrugDescription", "Amoxicillin 250mg/5ml Suspension");
            writer.WriteStartElement("DrugCoded");
            writer.WriteElementString("ProductCode", "00003173840");
            writer.WriteElementString("ProductCodeQualifier", "ND");
            writer.WriteElementString("DosageForm", "61");
            writer.WriteEndElement();

            writer.WriteStartElement("Quantity");
            writer.WriteElementString("Qualifier", "ME");
            writer.WriteElementString("Value", "60");
            writer.WriteEndElement();

            writer.WriteStartElement("Directions", "Take one teaspoonsful by mouth daily.");
            writer.WriteEndElement();
            //Should be <Directions>Take one teaspoonsful by mouth daily.</Directions>
            writer.WriteRaw("Note />");

            writer.WriteStartElement("Refills");
            writer.WriteElementString("Qualifier", "R");
            writer.WriteElementString("Quantity", "02");
            writer.WriteEndElement();

            writer.WriteStartElement("Substitutions", "0"); writer.WriteEndElement();
            //  Should be <Substitutions>0</Substitutions>

            writer.WriteStartElement("WrittenDate", "20060322");
            writer.WriteEndElement();
            // Should be <WrittenDate>20060322</WrittenDate>

            writer.WriteStartElement("LastFillDate", "20060324");
            writer.WriteEndElement();
            //Should be <LastFillDate>20060324</LastFillDate>


            writer.WriteEndElement();

            writer.WriteEndElement();

            writer.WriteEndElement();

            writer.WriteEndElement();


            writer.Close();


Thanks!!!

Jerry
0
Comment
Question by:JDL129
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 2000 total points
ID: 39244185
do u have the expected xml for reference?
also u can't have element name with space inside, so this line will cause malformed xml:
writer.WriteElementString("Address Line 1", "1922 N Carbon City Rd");

Open in new window

you should use:
writer.WriteElementString("AddressLine1", "1922 N Carbon City Rd");

Open in new window

or
writer.WriteElementString("Address_Line_1", "1922 N Carbon City Rd");

Open in new window

0
 

Author Comment

by:JDL129
ID: 39245130
sedgwick!!  Thanks for the post!!

The expected information is  below in the Should  be line

Thanks

Jerry
0
 

Author Comment

by:JDL129
ID: 39245275
sedgwick!!  This is what I am trying to create:

<Message xmlns="http://www.surescripts.com/messaging">
   <Header>
      <To>mailto:4736190679001.spi@surescripts.com</To>
      <From>mailto:1111111.ncpdp@surescripts.com</From>
      <MessageID>333c32da7169436fbc703153bd722d34</MessageID>
      <SentTime>2006-06-23T21:19:04.9Z</SentTime>
   </Header>
   <Body>
      <RefillRequest>
         <RxReferenceNumber>FMEM-999512</RxReferenceNumber>
         <PrescriberOrderNumber>ORD-888512</PrescriberOrderNumber>
         <Pharmacy>
            <Identification>
               <NCPDPID>1111111</NCPDPID>
            </Identification>
            <StoreName>4 Rx</StoreName>
            <Address>
               <AddressLine1>C St</AddressLine1>
               <City>Eagle</City>
               <State>VA</State>
               <ZipCode>22602</ZipCode>
            </Address>
            <PhoneNumbers>
               <Phone>
                  <Number>3334444444</Number>
                  <Qualifier>TE</Qualifier>
               </Phone>
               <Phone>
                  <Number>4443332222</Number>
                  <Qualifier>FX</Qualifier>
               </Phone>
            </PhoneNumbers>
         </Pharmacy>
         <Prescriber>
            <Identification>
               <SPI>4736190679001</SPI>
            </Identification>
            <Name>
               <LastName>Greiner</LastName>
               <FirstName>Ann</FirstName>
               <MiddleName>G.</MiddleName>
               <Suffix>M.D.</Suffix>
               <Prefix>Dr.</Prefix>
            </Name>
            <Address>
               <AddressLine1>30 Hunter Lane</AddressLine1>
               <City>Camp Hill</City>
               <State>PA</State>
               <ZipCode>170112400</ZipCode>
            </Address>
            <PhoneNumbers>
               <Phone>
                  <Number>9175556767</Number>
                  <Qualifier>TE</Qualifier>
               </Phone>
               <Phone>
                  <Number>9175556868</Number>
                  <Qualifier>FX</Qualifier>
               </Phone>
            </PhoneNumbers>
         </Prescriber>
         <Patient>
            <Identification>
               <SocialSecurity>738473829</SocialSecurity>
            </Identification>
            <Name>
               <LastName>Richardson</LastName>
               <FirstName>Douglas</FirstName>
               <MiddleName>R.</MiddleName>
            </Name>
            <Gender>M</Gender>
            <DateOfBirth>19980921</DateOfBirth>
            <Address>
               <AddressLine1>23 Trumble Dr.</AddressLine1>
               <AddressLine2>Apt 101</AddressLine2>
               <City>Holyoke</City>
               <State>MA</State>
               <ZipCode>01040</ZipCode>
            </Address>
            <PhoneNumbers>
               <Phone>
                  <Number>4137760938</Number>
                  <Qualifier>TE</Qualifier>
               </Phone>
               <Phone>
                  <Number>4137762738</Number>
                  <Qualifier>NP</Qualifier>
               </Phone>
            </PhoneNumbers>
         </Patient>
         <MedicationPrescribed>
            <DrugDescription>Amoxicillin 250mg/5ml Suspension</DrugDescription>
            <DrugCoded>
               <ProductCode>00003173840</ProductCode>
               <ProductCodeQualifier>ND</ProductCodeQualifier>
               <DosageForm>61</DosageForm>
            </DrugCoded>
            <Quantity>
               <Qualifier>ME</Qualifier>
               <Value>0060</Value>
            </Quantity>
            <Directions>Take one teaspoonsful by mouth daily.</Directions>
            <Note />
            <Refills>
               <Qualifier>R</Qualifier>
               <Quantity>02</Quantity>
            </Refills>
            <Substitutions>0</Substitutions>
            <WrittenDate>20060322</WrittenDate>
            <LastFillDate>20060324</LastFillDate>
         </MedicationPrescribed>
      </RefillRequest>
   </Body>
</Message>


Thanks for your help!!!

Jerry
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:JDL129
ID: 39251874
Sedgwick!!!

Is there a problem?

Thanks,
Jerry
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39252081
Which .net version u use?
0
 

Author Comment

by:JDL129
ID: 39252252
C#
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39252338
.net version not language.
2.0/3.5/4.0?
0
 

Author Comment

by:JDL129
ID: 39253205
Sorry!! 3.5.
0
 

Author Closing Comment

by:JDL129
ID: 39267272
Thanks Mr. Sedgewick!!!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question