Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Best practice to handle processing XML files with different schemas

Best practice to handle processing XML files with different schemas

Scheduled Pinned Locked Moved XML / XSL
xmlcsharpcssdatabasediscussion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sking72
    wrote on last edited by
    #1

    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.

    S 1 Reply Last reply
    0
    • S sking72

      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.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      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!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups