Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Tue, 20 May 2008 08:00:14 +0200,    group: microsoft.public.xml        back       


XML : How to insert element between two elements ?   
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
date: Tue, 20 May 2008 08:00:14 +0200   author:   E.F

Re: How to insert element between two elements ?   
"E.F"  a écrit dans le message de news: 
u5rLH7juIHA.5892@TK2MSFTNGP02.phx.gbl...
> 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
date: Tue, 20 May 2008 08:07:52 +0200   author:   E.F

Re: How to insert element between two elements ?   
"E.F"  wrote in message 
news:Owpvb$juIHA.4260@TK2MSFTNGP05.phx.gbl...
> "E.F"  a écrit dans le message de news: 
> u5rLH7juIHA.5892@TK2MSFTNGP02.phx.gbl...
>> 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
date: Tue, 20 May 2008 08:25:33 +0100   author:   Joe Fawcett am

Re: How to insert element between two elements ?   
"Joe Fawcett" <joefawcett@newsgroup.nospam> a écrit dans le message de news: 
OWZ9xqkuIHA.524@TK2MSFTNGP05.phx.gbl...
> "E.F"  wrote in message 
> news:Owpvb$juIHA.4260@TK2MSFTNGP05.phx.gbl...
>> "E.F"  a écrit dans le message de news: 
>> u5rLH7juIHA.5892@TK2MSFTNGP02.phx.gbl...
>>> 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.
date: Tue, 20 May 2008 10:31:43 +0200   author:   E.F

Re: How to insert element between two elements ?   
"E.F"  wrote in message 
news:%23L97xPluIHA.4772@TK2MSFTNGP03.phx.gbl...
>
> "Joe Fawcett" <joefawcett@newsgroup.nospam> a écrit dans le message de 
> news: OWZ9xqkuIHA.524@TK2MSFTNGP05.phx.gbl...
>> "E.F"  wrote in message 
>> news:Owpvb$juIHA.4260@TK2MSFTNGP05.phx.gbl...
>>> "E.F"  a écrit dans le message de news: 
>>> u5rLH7juIHA.5892@TK2MSFTNGP02.phx.gbl...
>>>> 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
date: Wed, 21 May 2008 08:08:44 +0100   author:   Joe Fawcett am

Re: How to insert element between two elements ?   
"Joe Fawcett" <joefawcett@newsgroup.nospam> a écrit dans le message de news: 
%23q3dFGxuIHA.3780@TK2MSFTNGP03.phx.gbl...
> "E.F"  wrote in message 
> news:%23L97xPluIHA.4772@TK2MSFTNGP03.phx.gbl...
>>
>> "Joe Fawcett" <joefawcett@newsgroup.nospam> a écrit dans le message de 
>> news: OWZ9xqkuIHA.524@TK2MSFTNGP05.phx.gbl...
>>> "E.F"  wrote in message 
>>> news:Owpvb$juIHA.4260@TK2MSFTNGP05.phx.gbl...
>>>> "E.F"  a écrit dans le message de news: 
>>>> u5rLH7juIHA.5892@TK2MSFTNGP02.phx.gbl...
>>>>> 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
date: Fri, 23 May 2008 10:40:48 +0200   author:   E.F

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us