Skip to content

Use XML data as variable name

Carl Cioffi

Asked Jun 18, 2013, 11:22 AM EDT4 answers
Share
LinkedInX

I am trying to modify a value in a text file template with a value from a database table without hard coding the relationship between the template field and the database field.  I want to use an XML file to hold the names of the placeholders and database field names.

Placeholders look like: [somefieldname]
database fields look like: "databasefieldname"

XML looks like:

<placeholder>[somefieldname]</placeholder>
<dbfieldname>databasefieldname</dbfieldname>

Template looks like:

a,b,d,[somefieldname],y,n,1,2, etc...

Is this a crazy thought or is it actually feasible?

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    0
    looks pretty feasible but I'm not clear with the idea completely, please explain on that.
    0
  • 0
    There is data in a database table that needs to populate specific data in a  comma delimited file.  The data items are identified as placeholders and  are wrapped in [].  The placeholders are currently hard coded into an  application that reads the comma delimited file then replaces the placeholders  with the data from the database table.

    My plan is to move the list of  placeholders and the database table fields that replace them into an XML file so  when new placeholders are added/removed the code doesn't have to be opened  again.  We can just modify the XML and go.

    9,1,Y,N,[taxrate1],Y,N,  etc...

    database table field cTaxRate1 replaces [taxrate1] when program  executes.

    XML data would  have

    < placeholder>[taxrate1]</placeholder>
    < fieldname>cTaxRate1</fieldname>

    This  would eliminate future code changes when the comma delimited configuration file  becomes:

    [taxflag],1,Y,N,[taxrate1],Y,N, etc...
    0
  • Sunny  Sharma
    0
    Hi Carl,

    Got your point. Still I've a little to clear related to your text file.

    Is it like- a single value from database for every matching placeholder in file, or like a single database value for a single placeholder.

    I mean do we have only a single line having the placeholder like:

    a,b,d,[somefieldname],y,n,1,2, etc...

    or it could be multiple, like:

    a,b,d,[somefieldname],y,n,1,2, etc...
    a,b,d,[somefieldname],y,n,1,2, etc...
    a,b,d,[somefieldname],y,n,1,2, etc...
    a,b,d,[somefieldname],y,n,1,2, etc...

    OR, alternatively, you just show me your current code, and I'll give you the solution.
    Thanks.
    0
  • 0

    In trying to show you an example of what I am trying to do I solved the problem which was right in front of me but I couldn't see the forest from the trees.  I think I was just putting way too much thought into it.


    string placeHolder = "[State]";
    string fieldName = "cState";
    string txtValue = "Y,N,[State],N";
    txtValue = txtValue.Replace(placeHolder, row[fieldName].ToString());

    Where row is the datatable row with the replacement data.

    0