|
Hi
i opened the xml file and then after updating when i want to save it .It gives me Error
See the code
try
{
XmlNode xmlnode;
XmlDocument xdoc=new XmlDocument();
xdoc.Load(@"C:\VirtualDirectory\XmlApplication\myfile.xml");
XmlDocumentFragment docFrag=xdoc.CreateDocumentFragment();
docFrag.InnerXml="<add>this to it";
xmlnode=xdoc.DocumentElement.FirstChild;
xmlnode.InsertAfter(docFrag,xmlnode.LastChild);
xdoc.Save(@"C:\VirtualDirectory\XmlApplication\myfile.xml"); // Here it gives Error
}
catch(Exception ex)
{
ex.ToString();
}
|
|
|
|
|
Your code appears to be okay. However, your error may be based on your XML document structure. You need to post the error message!
Also, if you are using ASP.NET, you need to give ASP.NET the permission to write the file to the host server's file system.
-- modified at 15:06 Wednesday 31st May, 2006
|
|
|
|
|
Hi i am new developer for web application
In my web i want to update the existing xml file again and again for that i have some queries
1) What should i use for reading and writing the xml file
2) How we can add a new node/element in xml at perticular parent tag
-- modified at 3:20 Wednesday 31st May, 2006
|
|
|
|
|
sandeep akhare wrote: 1) What should i use for reading and writing the xml file
Which Language are you using
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Thanks for replying me i am using ASP.NET in which i am using C#
|
|
|
|
|
try this link
http://www.c-sharpcorner.com/Tutorials/ReadWriteXMLTutMellli21.asp
Regards
Shajeel
|
|
|
|
|
Thnak you very you solved my problem
|
|
|
|
|
Personally, I'd use something like SkeletonCrew[^] to build an XML serializable model, so that you can program against objects that mirror your XML structure. Deserialize the XML to objects, make whatever changes you need to do, and then serialize it back out to XML. Much quicker and easier than trying to do inserts with the XML DOM, and more flexible than being tied to DataSet, and it sticks to your model structure unlike the DataSet.
Visit BoneSoft.com
|
|
|
|
|
Hello,
I have an XML file of some network topology. The network elements are nested within each other. I want to read that XML file into a newly created Access databasea file. I dont have the schema of that XML file.
Thanks for Any help.
|
|
|
|
|
There may be an easier way, but the only thing I can think of is to build a little executable to process the XML and do the inserts for you. I'd use something like SkeletonCrew[^] to build an XML serializable model from your XML structure, so that you can program against objects that mirror your XML structure. It would make reading the XML data much easier. Then you just have to worry about your inserts as you work through the object structure.
I don't know of an existing tool that would do it for you, I'm affraid you'd have to build something to do it.
Visit BoneSoft.com
|
|
|
|
|
hi please anybody tell me how i can create xml file susing vb 6.0,its urgent
Thanks
|
|
|
|
|
Use the COM object of Microsoft.
Check your VB references for "Microsoft XML".
As far as I can remember....
Eran Aharonovich (eran.aharonovich@gmail.com )
Noviway
|
|
|
|
|
Hello...
Is it possible to add audio to an XML simpleviewer file that was created with Picasa or whatever file i would need to add the code to?
I have files titled: flashobject (jscript script file), imagedata.xml, the index.html, a readme, viewer (flash player movie file) and then the 2 image folders.....
I can provide the code..... Any help so much appreciated!
thanks so much.
|
|
|
|
|
Hey
So I have a XML with DataSet in it, in the DataSet I have 2 DataTables, in each DataTable I have a Unique ID, and I did to this row, auto-inc, and don't allow DBNull, and it's readonly.
So when I try to do NewRow(), and add it without setting the ID column, it throws an Exception DataColumn 'ID' can't allow DBNull.
So how can I do it as UNIQUE ID? do I need to allow DBNull?
|
|
|
|
|
Unique ID is similar to a primary key in some ways. It doesn't allow null. If you need nulls, you should use a regular data type with a more advanced constraint.
Keep in mind that XSD uinque IDs are document (DataSet) unique, not table unique.
|
|
|
|
|
But how can I insert a row in the DataTable with a unique ID (the next that should be)?
like if i have 5 rows and IDs 1-5, how can I add a new row with ID = 6? when it's readonly (can't edit it) and doesn't allow nulls?
|
|
|
|
|
If whatever component you're using to manipulate the XML doesn't automatically manage unique IDs, your best bet is probably to use int fields for your IDs and use a library function to manage this.
It's easy enough to write your own, although this is a well-solved problem so there's most likely one in whatever system you're running. Basically, you just need to store the next ID for each table, and write a function to retrieve it and increment each time.
|
|
|
|
|
Hi,
I wrote a program to extract part of XML elements, fill in the dataset with extracted elements,and display them in dataGridView (C++).e.g. : to extract only ADDRESSES and display the Id,Street,Postcode, city and country as the table columns in dataGridView
<MEMBER>
<GENDER>FEMALE</GENDER>
<AGE>35</AGE>
- <ADDRESSES>
- <ADDRESS>
<ID>1</ID>
<STREET>cranbrook ave</STREET>
<POSTCODE>1231231</POSTCODE>
<CITY>NOTTINGHAM</CITY>
<COUNTRY>UK</COUNTRY>
</ADDRESS>
- <ADDRESS>
<ID>2</ID>
<STREET>Wisteria Lane</STREET>
<POSTCODE>2452434</POSTCODE>
<CITY>FAIRVIEW</CITY>
<COUNTRY>US</COUNTRY>
</ADDRESS>
</ADDRESSES>
</MEMBER>
I have done the extraction with Xpath, append the extracted xml results node list with Stringbuilder and display them first in a text box. Then a dataset read the text box and display the result in dataGridView.
However, i would like to enable users edit the dataGridView and save the changes to the original Xml file. Could anyone suggest how I could get around it? I am a newbie in XML and I am sorry if it's a trivia >_<
Many thanks in advance,
Shar
-- modified at 21:35 Saturday 27th May, 2006
|
|
|
|
|
Take a look at System.Data.DataSet.ReadXml(...) and then binding the appropriate tables to the DataGridView object.
|
|
|
|
|
Hello,
Many thanks for you reply I managed to display the extracted element (addresses) in DataGridView (binded to dataset that contains <ADDRESSES>) fine, but could not figure out a way to update the original xml file if the dataGrid is updated.
For example, I have the following in "addressTry.xml" :
<MEMBER>
<GENDER>FEMALE</GENDER>
<AGE>35</AGE>
- <ADDRESSES>
- <ADDRESS>
<ID>1</ID>
<STREET>cranbrook ave</STREET>
<POSTCODE>1231231</POSTCODE>
<CITY>NOTTINGHAM</CITY>
<COUNTRY>UK</COUNTRY>
</ADDRESS>
</ADDRESSES>
when user changes CITY to LONDON, the DataSet is updated. But I could not use DataSet.WriteXml(...) or XmlDataDocument.Save(..) to update original file as this will overwrite the whole xml file. i.e : the <MEMBER>,<GENDER>,<AGE> and their child elements will be deleted, replaced by only <ADDRESSES> elements from dataset.
So how could I update this to the original file (so only <ADDRESSES> element is affected, and <MEMBER>, <GENDER> and <AGE> stay the same?)
Many thanks for advice and suggestions,
Shar
-- modified at 13:44 Thursday 1st June, 2006
|
|
|
|
|
sepsep06 wrote: (binded to dataset that contains <addresses>)
that is the problem. The DataSet should load the entire file not just a part of it. XML DOM and/or serialization can only write the whole file. Updating discrete fields of data is what a Database is for not an XML file.
|
|
|
|
|
Hello,
Thanks again for your reply . For some reason I could not use database and all I have is an XML file. However, I have managed to solve this problem by forcing it to delete the <ADDRESSES> original children element first; and then use XpathNavigator to append children (from new updated dataset)to <ADDRESSES>. I dont think this is a very good way but it is the only working way I can think of.
Many thanks and regards,
Shar
-- modified at 20:34 Thursday 1st June, 2006
|
|
|
|
|
Hi
When I pass & to the function putnodeValue() under the IXMLDom, its converting it to &. The same thing happens for &gr; also, when &gr; is passed the value set is &gr.
How to avoid this, I want the exact value to be set which I am passing.
Pls help
|
|
|
|
|
http://www.w3.org/TR/2004/REC-xml-20040204/#charsets[^]
The following quoted from that page:
The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings "&" and "<" respectively. The right angle bracket (>) MAY be represented using the string ">", and MUST, for compatibility, be escaped using either ">" or a character reference when it appears in the string "]]>" in content, when that string is not marking the end of a CDATA section.
-- modified at 23:46 Friday 26th May, 2006
|
|
|
|
|
Actually my problem is I am reading a CSV file and conveting it into XML, when one of the comma seperated value is &. I read it and set the value to the XML using IXMLDomNode's put_nodeValue() function in VC++. But the resulting output is &amp;.
Similarly when I pass > its converted to &gt;
How to over come this problem, the put_nodeValue() function is converting & to &
Is there any escape sequence to be added so that & is read as &
Thanks in Advance
|
|
|
|