Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Trouble creating an xml file in C#

Posted on 2013-06-13
9
Medium Priority
?
361 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:
Meir Rivkin 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:JDL129
ID: 39251874
Sedgwick!!!

Is there a problem?

Thanks,
Jerry
0
 
LVL 42

Expert Comment

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

Author Comment

by:JDL129
ID: 39252252
C#
0
 
LVL 42

Expert Comment

by:Meir Rivkin
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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

647 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