|
Why not do this in memory? i.e. Why save the possibly invalid file to begin with?
|
|
|
|
|
I'm not sure how to do it in memory.
Also, if it does turn out to be valid, I need to create the XML file.
|
|
|
|
|
In memory just means writing the XML to a string variable. How you do it depends on your current method of generating the XML and saving it to a file.
//e.g. with XmlTextWriter
XmlTextWriter xmlTextWriter = new XmlTextWriter(fileName, encoding);
//saves to a file.
StringBuilder sb = new StringBuilder()
XmlTextWriter xmlTextWriter = new XmlTextWriter(new StringWriter(sb));
//allows you to save to a string.
string myString = sb.ToString();
//Use:
xmlDocument.LoadXml(myString);
//before validating and saving the XmlDocument
Good Luck!
|
|
|
|
|
I can't help but wonder what the purpose of the schema would be. All you'd be doing there is validating that the DataTable you've just written to xml is in the schema of the datatable, which it would be every time.
What exactly are you trying to achieve here?
|
|
|
|
|
The schema would be used to generate the XML for input to another application.
|
|
|
|
|
I got 2 abstract classes that look somewhat like this:
<code> public abstract class vBase
{
public abstract int ID { get; set; }
public abstract string Group { get; }
}
public abstract class ListVBase
{
public abstract List<vBase> Items;
public abstract int Count {get;}
public abstract void Fill();
}</code>
However it is not possible to make an abstract list like that (the bold part). Anybody got an good idea for a work around? (what i need is an abstract class which hold a collection of vBase).
/Jan
|
|
|
|
|
Your vBase class is entirely abstract, so why not make it an interface? Then you could do this:
public interface vBase
{
int ID{ get; set; }
string Group { get ; }
}
public abstract class ListVBase<T> where T : vBase
{
public abstract List<T> Items;
public abstract int Count { get ; }
public abstract void Fill();
}
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I'm working on an existing system which operates on large XML files, but the areas of interest at any given point are relatively small.
So i've begun moving the small regions across to an object model, which i will serialize into / out of the existing XML document in the appropriate places in fragments.
My problem is, the XMLSerializer generates the XMLFile Declaration and NameSpace attributes in the root element, which makes the end result a complete XML Document, as opposed to a fragment that is part of a larger doc.
Is there any way to avoid the generation / requirement of the XML Serialization attributes so that it is actualy a Fragment?
Cheers
Tris
|
|
|
|
|
When you write from the XmlSerializer, you can use an XmlWriter (as a TextWriter). Use the static Create method off of XmlWriter to make a writer that has XmlWriterSettings. Using the settings, you can tell it to not put the declarations.
|
|
|
|
|
Thanks Dustin, that's just the ticket.
One last thing - is it possible to remove the xmlns:xsi and xmlns:xsd attributes using settings?
I've had a play around, but they are staying put.
Cheers
Tris
|
|
|
|
|
That one's a bit tougher. Are you using namespaces in the attributes on the type?
|
|
|
|
|
I finally got to a dev environment where I could test it. There really isn't a way to wipe those attributes off of there, which I think is a very frustrating part of using XmlSerializer. Some of the tactics I've taken in the past are to implement IXmlSerializable (which isn't fun because you have to read and write from the xml stream yourself) or to load the serialized xml into an XmlDocument and remove the namespaces manually. I'm not sure if MVPXML[^] has done anything to handle this but you may want to check it out.
|
|
|
|
|
Hi All,
Please help..
How to delete a row from Datagrid in CodeBehind ??
Thanks in advance..
|
|
|
|
|
You don't delete it from the datagrid. Delete it from your datasource.
only two letters away from being an asset
|
|
|
|
|
hi,
first of all create a template column , add an imagebutton on that and set Command Name property of that imagename as Delete. Defind DataKey of the datagrid as whatever ID or Field you want to use to delete the record from DB. Now write the follwing code:
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
int ID = Convert.ToInt32(DataGridInventory.DataKeys[e.Item.ItemIndex]);
//Pass this ID to the stored procedure where you have to write delete query.
or
SqlConnection con=new SqlConnection("<connectioname>");
con.Open();
SqlCommand cmd=new SqlCommand();
cmd.CommandText="delete form Table1 where id="
+ID";
cmd.Connection=con;
cmd.ExecuteNonQuery();
con.Close();
}
catch(Exception ex)
{
con.Close();
string strMsg=ex.Message;
}
}
|
|
|
|
|
|
the code segment that u sent me
using (StreamWriter sw = new StreamWriter filename)) { <br />
try<br />
{<br />
foreach (DataRow row in myDataTable)<br />
{ <br />
sw.WriteLine(row["columnName1"]);<br />
sw.WriteLine(row["columnName2"]);
sw.WriteLine("<body>");<br />
sw.WriteLine("" + row["columnName1"]);<br />
sw.WriteLine("</body>")
}<br />
}<br />
catch (Exception er)<br />
{
}<br />
finally<br />
{ sw.Close(); }<br />
}
gives me a syntax error
foreach statement cannot operate on variables of type 'System.Data.DataTable' because 'System.Data.DataTable' does not contain a definition for 'GetEnumerator', or it is inaccessible<br />
what am i doing wrong??
|
|
|
|
|
Replace
foreach (DataRow row in myDataTable)
by
foreach (DataRow row in myDataTable.Rows)
Regards
Shajeel
|
|
|
|
|
u're the brainiest
Regards
Saira
|
|
|
|
|
You need to iterate over myDataTable.Rows.
foreach (DataRow row in myDataTable.Rows)
Sometimes it's the little things that catch us out.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Yep, my fault. Sorry. Hope you got it working!
|
|
|
|
|
Hello every one,
well I've encountered a really weird eror in datagridview here. I'm workin in C# 2.0 windows form application and there is a dgv(datagridview) on it that is attached to a view..I added an unbound column in it to take the quantity from the user. Now when I get the value of quantity from a cell of that column I get a null when I put 1 in that cell where is its always the correct value whenever its not 1. Can any buddy plz tell me whats happening here. I receive the correct value when its 0, 2, 3 4 ... but its a null when its 1... What should I do.. is it a bug in VS or what??
thanks in advance
Rocky
|
|
|
|
|
can u post ur code to give an idea what u r doin
o O º(`'·.,(`'·., ☆,.·''),.·'')º O o°
»·'"`»* *☆ t4ure4n ☆* *«·'"`«
°o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°
|
|
|
|
|
well I sorted out that wrror by making a new column with a different name and I deleted that column but it was weird u know...
|
|
|
|
|
How are you attaching it to the view, through a bindingsource or just saying DGV.DataSource=theView; Also, how are you trying to access the value of the cell?
|
|
|
|