Best practice to handle processing XML files with different schemas
-
I am writing a program that will be processing XML files. There are roughly 5 schemas involved. I should tell you now that I'm not using C# but a language called ABAP (SAP), although I think that's largely irrelevant. The pseudocode for how this works is as follows:
OPEN FILE file AS TEXT. WHILE NOT EOF APPEND LINE OF file INTO xml_string. END. CALL TRANSFORMATION my_transformation USING xml_string INTO my_table.
Originally, there was just one schema and one transformation (a transformation is a small program in SAP that is used to take the XML string and turn it into something called an "internal table" - think of it as a DataTable for you C# developers). Now that we've got different schemas, however, I need a way to know which one to call based upon the type of file. I've thought of two ways but if someone else has a better idea I'd love to know! 1) Use something in the filename to indicate the type of schema 2) Use an attribute in the root element to indicate the file type: <envelope ftype='terminations'> ... </envelope> Unfortunately, with this approach I'd have to parse the first line of the file manually in my program as ABAP doesn't natively handle XML files very easily so it would be less work to do that. So, I'm leaning that way but I wanted a second opinion. Thanks in advance. -
I am writing a program that will be processing XML files. There are roughly 5 schemas involved. I should tell you now that I'm not using C# but a language called ABAP (SAP), although I think that's largely irrelevant. The pseudocode for how this works is as follows:
OPEN FILE file AS TEXT. WHILE NOT EOF APPEND LINE OF file INTO xml_string. END. CALL TRANSFORMATION my_transformation USING xml_string INTO my_table.
Originally, there was just one schema and one transformation (a transformation is a small program in SAP that is used to take the XML string and turn it into something called an "internal table" - think of it as a DataTable for you C# developers). Now that we've got different schemas, however, I need a way to know which one to call based upon the type of file. I've thought of two ways but if someone else has a better idea I'd love to know! 1) Use something in the filename to indicate the type of schema 2) Use an attribute in the root element to indicate the file type: <envelope ftype='terminations'> ... </envelope> Unfortunately, with this approach I'd have to parse the first line of the file manually in my program as ABAP doesn't natively handle XML files very easily so it would be less work to do that. So, I'm leaning that way but I wanted a second opinion. Thanks in advance.Ummm - there are various ways of inidicating the schema in use - usually use of different namespaces, on eper schema. The namespace declaration attribute is generally on the root node of the document. Alternatively, there is a specific namespace and set of attributes[^] that can be used to show what schema is in use.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!