XMLWriter Question - InfoPath Dev
in

InfoPath Dev

XMLWriter Question

Last post 12-18-2012 11:19 AM by xjoutsider. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 12-17-2012 01:10 PM

    XMLWriter Question

    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

    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 MVP
    Qdabra Software
  • 12-18-2012 03:00 AM In reply to

    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

    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.