Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: How to insert element between two elements ? [Thread Next] Re: How to insert element between two elements ?To: NULL Date: 5/23/2008 10:41:00 AM "Joe Fawcett" <joefawcett@n...> a écrit dans le message de news: %23q3dFGxuIHA.3780@T...... > "E.F" <fenouillet.et@l...> wrote in message > news:%23L97xPluIHA.4772@T...... >> >> "Joe Fawcett" <joefawcett@n...> a écrit dans le message de >> news: OWZ9xqkuIHA.524@T...... >>> "E.F" <fenouillet.et@l...> wrote in message >>> news:Owpvb$juIHA.4260@T...... >>>> "E.F" <fenouillet.et@l...> a écrit dans le message de news: >>>> u5rLH7juIHA.5892@T...... >>>>> Hi, >>>>> >>>>> I need to insert the following element : >>>>> <QUATRE Attr_1="400" Attr_2="100" /> >>>>> in my xml file witch is looking like that : >>>>> >>>>> <TEST> >>>>> <Etape_1> >>>>> <NEUF Attr_1="400" Attr_2="100" /> >>>>> <DIX Attr_1="400" Attr_2="100" /> >>>>> <ONZE Attr_1="400" Attr_2="100" /> >>>>> </Etape_1> >>>>> <Etape_2> >>>>> <UN Attr_1="400" Attr_2="100" /> >>>>> <DEUX Attr_1="400" Attr_2="100" /> >>>>> <TROIS Attr_1="400" Attr_2="100" /> >>>>> >>>>> -----> here is the place where my element shoud be >>>>> inserted<----------- >>>>> >>>>> <CINQ Attr_1="400" Attr_2="100" /> >>>>> </Etape_2> >>>>> </TEST> >>>>> >>>>> Does anybody can show me the way to do ? >>>>> >>>>> Thank you for your attention, >>>>> >>>>> Etienne >>>>> >>>> >>>> Sorry ! >>>> I forgot to say that I manage my xml file with vb.net >>>> >>>> >>> Do you know it will go between TROIS and CINQ or do you have to >>> translate the element names into numerals first? >>> (This seems like a really bad XML structure: >>> <Test> >>> <Etape numero="1"><article numero="1"/><article numero="1"/><article >>> numero=""3/></Etape> >>> <Etape numero="2"><article numero="1"/><article numero="1"/><article >>> numero=""3/></Etape> >>> </Test> >>> would be much easier to work with. >>> >>> -- >>> >>> Joe Fawcett (MVP - XML) >>> >>> http://joe.fawcett.name >> >> Thank you for your reply. >> >> Each time i use my application, i have to check that all the previous >> elements >> have not been deleted. >> >> Then I read my xml file with xmlreader, and if any element is missing >> (element >> FOUR for exemple), I have this msgBox : >> >> "Element FOUR, is missing. Do you want to add it ?", vbyesno >> >> If I replay Yes, i know where I have to insert the missing element (with >> any >> attributs) in then xml, but I'm unable to do it. >> > To insert a node using DOM you can use insertAfter which needs reference > to the new node and the preceding one. > See > http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.insertafter.aspx > > You are using an XmlReader though so you may want to use XmlWriter to > create the document. It really depends on how big the document is, to use > XmlDocument you need to load the whole document into memory but using > XmlWriter you'll need to run through the whole document with XmlReader and > write out to a new document with the change required and then save over > the original. > > See http://blogs.msdn.com/mfussell/archive/2005/02/12/371546.aspx > > -- > > Joe Fawcett (MVP - XML) > > http://joe.fawcett.name Thank you Joe for your help | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
