Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How to insert element between two elements ?

From: "Joe Fawcett" <joefawcett@---------.------>
To: NULL
Date: 5/21/2008 8:09:00 AM

"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





transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent