tags:

views:

67

answers:

1

Hi all,

We are communicating with a 3rd party service using via an XML file based on standards that this 3rd party developed. They give us an XML template for each "transaction" and we read it into a DataSet using System.Data.DataSet.ReadXML, set the proper values in the DataSet, and then write the XML back using System.Data.DataSet.WriteXML. This process has worked for several different files. However, I am now adding an additional file which requires that an integer data type be set on one of the fields. Here is a scaled down version:

<EngineDocList>
    <DocVersion>1.0</DocVersion>
    <EngineDoc>
        <MyData>
            <FieldA></FieldA>
            <FieldB></FieldB>
            <ClientID DataType="S32"></ClientID>
        </MyData>
    </EngineDoc>
</EngineDocList>

When I look at the DataSet created by my call to ReadXML to this file, the MyData table has columns of FieldA, FieldB, and MyData_ID. If I then set the value of MyData_ID and then make the call to WriteXML, the export XML has no value for ClientID. Once again, if I take a way the DataType, then I do have a ClientID column, I can set it properly, and the exported XML has the proper value. However, the third party requires that this data type be defined.

Any thoughts on why the ReadXML would be renaming this tag or how I could otherwise get this process to work? Alternatively, I could revamp the way we are reading and writing the XML, but would obviously rather not go down this path although these suggestions would also be welcome. Thanks.

+2  A: 

I would not do this with a DataSet. It has a specific focus on simulating a relational model. Much XML will not follow that model. When the DataSet sees things that don't match it's idea of the world, it either ignores them or changes them. In neither case is it a good thing.

I'd use an XmlDocument for this.

John Saunders
Good points. I'm using an internal library that was developed before I came here and was trying to keep things consistent (and time spent on the task low), but it could very well be a square peg in a round hole and require some rearchitecture.
AdamB
Yup, square peg, round hole. This was easy enough to change over to use the XMLDocument class. Thanks for the direction.
AdamB