Loading XML from TypedView

Posts   
 
    
Posts: 35
Joined: 10-Sep-2006
# Posted on: 01-Dec-2006 23:36:15   

Ok - I have a typed view. I'm having a problem when I take the xml from the typed view and try to load it into an XML document. I keep getting invalid root node. For instance...


//tl is a loaded typedview
//I get invalid root node
MemoryStream myXMLStream = new MemoryStream();
tl.WriteXml(myXMLStream,true);

XmlDocument doc = new XmlDocument() ;
doc.Load(myXMLStream);

but


//tl is a loaded typedview
//I get invalid root node
MemoryStream myXMLStream = new MemoryStream();
tl.WriteXml("c:\\foo.xml");

XmlDocument doc = new XmlDocument() ;
doc.Load("c:\\foo.xml");

works fine!!!

What am I missing here?! Have I been looking at this for too long?!

The view does include a column of encrypted data (using tripleDes but I used base64endoing in it) and I add a column in the typed list - and add the unencrypted data there.

Thats another question - is that the best way to to that via LLBL.. I have a column in my typedlist that hold encrypted data. I add a new column of type string - loop the typed view setting the new column to the decryped value?

Hope this all makes sence..

Posts: 35
Joined: 10-Sep-2006
# Posted on: 01-Dec-2006 23:50:45   

Doh!!! confused never mind... found it.. it just dawned on my my stream was at the end.. so a simple. Too long staring at this thing!! myXMLStream.position = 0; worked like a champ..

But my other question still it out there concerning the encrypted data -

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 02-Dec-2006 23:43:05   

HammerManinMD wrote:

Thats another question - is that the best way to to that via LLBL.. I have a column in my typedlist that hold encrypted data. I add a new column of type string - loop the typed view setting the new column to the decryped value?

Sorry, but I'm not following what you're doing with the new column of type string. Are you trying to decrypt the encrypted column into this new column?

Posts: 35
Joined: 10-Sep-2006
# Posted on: 04-Dec-2006 02:22:47   

Sorry at times I tend to ramble. Ok I have a view in my database that is made up of about 5 tables. One column that is returned from the view contains encrypted data. I have a typed view to access the data in this view from my application. So I get back for all intents and purposes a readonly datatable that is the typed view. I need to display the data to the users that is encrypted - but I need to decrypt the data.

I'm not simply binding to a datagrid - I'm using the resulting xml from the datatable (typedview) and using it in an XSLT transformation- and then using xslfo to generate a pdf. So if this was a typical scenerio on the data item bound event and decrypt and display the data. That won't work in this case.

What I did to make this work is add a new column to the datatable. Loop the table row collection and decrypt the encrypted column then set the column I just created with the unencrypted data.

Example



UvMasterReviewTypedView tl = new UvMasterReviewTypedView();
        DataAccessAdapter da = new DataAccessAdapter();

        da.FetchTypedView(tl);

        tl.Columns.Add(new DataColumn("DecryptedResponse",typeof(string)));
    
        foreach (UvMasterReviewRow r in tl.Rows)
        {
            r["DecryptedResponse"] = Utility.DecryptTripleDES(r.Response);

        }

Now what I was wonder is there a way to facilitate this column in the typedview different than how I'm doing this. I was able to change the .readonly property of the attribute in the generated class - but when I added the code to the user code area in the class it didn't work correctly - I tried to dynamically in the class and make its readonly propery to false - but I couldn't get that to work.

thoughts? Ideas?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Dec-2006 07:55:05   

Your scenario should work. Another alternative is to use a new DataTable which should have the extra column and it may not have the encrypted column. And then copy data from the typed view into the new dataTable and transform/decrypt the encrypted column.

Back to your scenario:

but when I added the code to the user code area in the class it didn't work correctly

Please elaborate more with a code snippet and specify what did you mean by "it didn't work"

Posts: 35
Joined: 10-Sep-2006
# Posted on: 04-Dec-2006 15:42:00   

ok - here is the code I tried to add into the typedview class - what did I miss?



// __LLBLGENPRO_USER_CODE_REGION_START AdditionalMembers
        private DataColumn _columnDecryptedData;
// __LLBLGENPRO_USER_CODE_REGION_END

// __LLBLGENPRO_USER_CODE_REGION_START AdditionalFields
// be sure to call _fields.Expand(number of new fields) first. 
            _fields.Expand(1);
            _columnDecryptedData = new DataColumn("DecryptedData", typeof(String), null, MappingType.Element);
            _columnDecryptedData.ReadOnly = false;
            _columnDecryptedData.Caption = @"DecryptedData";
            this.Columns.Add(_columnDecryptedData);
// __LLBLGENPRO_USER_CODE_REGION_END

// __LLBLGENPRO_USER_CODE_REGION_START InitMembers
            _columnDecryptedData = this.Columns["DecryptedData"];
// __LLBLGENPRO_USER_CODE_REGION_END


I'm sure I'm missing some pices to this here... what other code do I need to add to get a custom view column into the classa?

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 04-Dec-2006 16:05:33   

Hello,

Have you got any error during the initialisation of the new column? Is the column empty or is the column not appear?

Posts: 35
Joined: 10-Sep-2006
# Posted on: 04-Dec-2006 19:39:03   

I don't see that column in my field collection..

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Dec-2006 08:02:23   

You sould add a property for the new column as follows:

            
// __LLBLGENPRO_USER_CODE_REGION_START AdditionalColumnProperties
internal DataColumn DecryptedDataColumn 
{
    get { return _columnDecryptedData; }
}
// __LLBLGENPRO_USER_CODE_REGION_END

// __LLBLGENPRO_USER_CODE_REGION_START CustomTypedViewRowCode
public System.String DecryptedData
{
    get 
    {
        if(IsNull(_parent.DecryptedDataColumn))
        {
            // return default value for this type.
            return (System.String)TypeDefaultValue.GetDefaultValue(typeof(System.String));
        }
        else
        {
            return (System.String)this[_parent.DecryptedDataColumn];
        }
    }
    set 
    {
        this[_parent.DecryptedDataColumn] = value;
    }
}
// __LLBLGENPRO_USER_CODE_REGION_END

Then in the Additional Fields user code region you should have:

// __LLBLGENPRO_USER_CODE_REGION_START AdditionalFields
// be sure to call _fields.Expand(number of new fields) first. 
            _fields.Expand(1);
// __LLBLGENPRO_USER_CODE_REGION_END

And move the rest of what you had into the InitClass code region:


// __LLBLGENPRO_USER_CODE_REGION_START InitClass
_columnDecryptedData = new DataColumn("DecryptedData", typeof(String), null, MappingType.Element);
_columnDecryptedData.ReadOnly = false;
_columnDecryptedData.Caption = @"DecryptedData";
this.Columns.Add(_columnDecryptedData);
// __LLBLGENPRO_USER_CODE_REGION_END

Leave your code in the AdditionalMembers & InitMembers code regions as they are.