XMLWriter Question - InfoPath Dev Sign in | Join | Help in Code InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Code » XMLWriter Question XMLWriter Question Last post 12-18-2012 11:19 AM by xjoutsider. 3 replies. Page 1 of 1 (4 items) Sort Posts: Oldest to newest Newest to oldest Previous Next 12-17-2012 01:10 PM xjoutsider Joined on 03-01-2011 Posts 27 XMLWriter Question Reply Contact I am working with the XMLWriter method and i find my self stuck with group labled File_Layout. Can it be included in the writer or do i have to do something specical? What how do you work with Dates and File attach feilds with Writer ? This is what i got so far. public void Insert_INPUT_File_Clicked(object sender, ClickedEventArgs e) {string myNamespace = NamespaceManager.LookupNamespace("my"); using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Section_D_Target_Pop_Req/my:Input_file_Req", NamespaceManager).AppendChild()) {writer.WriteStartElement("Sub-Section_D1_Input_File_Req", myNamespace); writer.WriteElementString("Input_File_Requirement_Count", myNamespace, "cell1");writer.WriteElementString("Input_File_Requirement_ID", myNamespace, ""); writer.WriteElementString("Input_File_Name", myNamespace, "");writer.WriteElementString("Input_File_Requirement_Description", myNamespace, ""); writer.WriteElementString("Input_File_Contact_Name", myNamespace, "");writer.WriteElementString("Input_File_Phone_Number", myNamespace, ""); writer.WriteElementString("Input_File_Format", myNamespace, "");writer.WriteElementString("Input_File_Location", myNamespace, ""); writer.WriteElementString("Input_File_Date_for_Pickup", myNamespace, "");writer.WriteElementString("External_Input_File_Exception_Form", myNamespace, ""); writer.WriteElementString("External_Input_File_Exception_Approval_Email", myNamespace, "");writer.WriteElementString("Input_File_Remove", myNamespace, "");writer.WriteElementString("File_Layout", myNamespace, ""); writer.WriteEndElement(); writer.Close(); } } 12-17-2012 06:33 PM In reply to Jimmy Joined on 07-03-2008 Posts 2,595 Re: XMLWriter Question Mark as Not AnswerMark as Answer... Reply Contact Are you encountering a particular issue? If so, what is it? You shouldn't need anything particularly special for File_Layout, though there's a slight chance that WriteElementString() might not work for File_Layout since it's a group. You may want to try writer.WriteStartElement("File_Layout", myNamespace);writer.WriteEndElement();For dates, file fields, and numbers, you'll typically need to add an xsi:nil attribute when you create them if they're going to start off blank:writer.WriteStartElement("Input_File_Date_for_Pickup", myNamespace);writer.WriteAttributeString("xsi", "nil", System.Xml.Schema.XmlSchema.InstanceNamespace, "true");writer.WriteEndElement(); Jimmy Rishe / Software Developer / Microsoft MVPQdabra Software 12-18-2012 03:00 AM In reply to xjoutsider Joined on 03-01-2011 Posts 27 Re: XMLWriter Question Mark as Not AnswerMark as Answer... Reply Contact The problem is the file layout section does not write if I add all the fields it. It throws data validation erroring on writer.close() I will try your suggestion I was not sure if I had to start anther instance of the writer or not? To add the file layout section 12-18-2012 11:19 AM In reply to xjoutsider Joined on 03-01-2011 Posts 27 Re: XMLWriter Question Mark as Not AnswerMark as Answer... Reply Contact I still have not figured it out. I am a little closer it just does not seem to write to the correct line on the structure. it onlly wants to insert the row on the first row of the the File type. string myNamespace = NamespaceManager.LookupNamespace("my"); using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Section_D_Target_Pop_Req/my:Input_file_Req", NamespaceManager).AppendChild()) {writer.WriteStartElement("Sub-Section_D1_Input_File_Req", myNamespace); writer.WriteElementString("Input_File_Requirement_Count", myNamespace, "cell1");writer.WriteElementString("Input_File_Requirement_ID", myNamespace, ""); writer.WriteElementString("Input_File_Name", myNamespace, "");writer.WriteElementString("Input_File_Requirement_Description", myNamespace, ""); writer.WriteElementString("Input_File_Contact_Name", myNamespace, "");writer.WriteElementString("Input_File_Phone_Number", myNamespace, ""); writer.WriteElementString("Input_File_Format", myNamespace, "");writer.WriteElementString("Input_File_Location", myNamespace, ""); writer.WriteElementString("Input_File_Date_for_Pickup", myNamespace, "");writer.WriteElementString("External_Input_File_Exception_Form", myNamespace, ""); writer.WriteElementString("External_Input_File_Exception_Approval_Email", myNamespace, "");writer.WriteElementString("Input_File_Remove", myNamespace, ""); writer.WriteEndElement(); writer.Close(); }using (XmlWriter innerwriter = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Section_D_Target_Pop_Req/my:Input_file_Req/my:Sub-Section_D1_Input_File_Req/my:File_Layout", NamespaceManager).AppendChild()) { innerwriter.WriteStartElement("Input_File_Layout_Fields", myNamespace);innerwriter.WriteElementString("Field_Name", myNamespace, ""); innerwriter.WriteElementString("Data_Type", myNamespace, "");innerwriter.WriteElementString("Start_Postion", myNamespace, ""); innerwriter.WriteElementString("End_Postion", myNamespace, "");innerwriter.WriteElementString("Postion", myNamespace, ""); innerwriter.WriteElementString("Length", myNamespace, "");innerwriter.WriteElementString("Remove", myNamespace, ""); innerwriter.WriteEndElement(); innerwriter.Close(); } Page 1 of 1 (4 items) Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
I am working with the XMLWriter method and i find my self stuck with group labled File_Layout. Can it be included in the writer or do i have to do something specical?
What how do you work with Dates and File attach feilds with Writer ?
This is what i got so far.
{
writer.WriteElementString(
writer.WriteEndElement();
writer.Close();
}
Are you encountering a particular issue? If so, what is it? You shouldn't need anything particularly special for File_Layout, though there's a slight chance that WriteElementString() might not work for File_Layout since it's a group. You may want to try
writer.WriteStartElement("File_Layout", myNamespace);writer.WriteEndElement();
writer.WriteStartElement("File_Layout", myNamespace);
For dates, file fields, and numbers, you'll typically need to add an xsi:nil attribute when you create them if they're going to start off blank:
writer.WriteStartElement("Input_File_Date_for_Pickup", myNamespace);writer.WriteAttributeString("xsi", "nil", System.Xml.Schema.XmlSchema.InstanceNamespace, "true");writer.WriteEndElement();
writer.WriteStartElement("Input_File_Date_for_Pickup", myNamespace);
writer.WriteAttributeString("xsi", "nil", System.Xml.Schema.XmlSchema.InstanceNamespace, "true");
I still have not figured it out. I am a little closer it just does not seem to write to the correct line on the structure. it onlly wants to insert the row on the first row of the the File type.
innerwriter.WriteStartElement(
innerwriter.WriteElementString(
innerwriter.WriteEndElement();
innerwriter.Close();