Home All Groups Group Topic Archive Search About

remove xml file root tag

Author
9 Nov 2006 2:12 PM
martin1
Hi, All,

the xml file is like this:

<Root>
<AutoData>
<Table1>
<Data1>  10 </Data1>
<Data2>  20 </Data2>
<Data3>  40 </Data3>
<Table1>
<Table2>
<Data1>  10 </Data1>
<Data2>  20 </Data2>
<Data3>  40 </Data3>
<Table2>
</AutoData>
</Root>

I want to remove Root open and close tag (<Root> and </Root>), can anyone
tell how?

Thanks for your time.

Martin

Author
9 Nov 2006 2:28 PM
Martin Honnen
martin1 wrote:

Show quoteHide quote
> <Root>
> <AutoData>
> <Table1>
> <Data1>  10 </Data1>
> <Data2>  20 </Data2>
> <Data3>  40 </Data3>
> <Table1>
> <Table2>
> <Data1>  10 </Data1>
> <Data2>  20 </Data2>
> <Data3>  40 </Data3>
> <Table2>
> </AutoData>
> </Root>
>
> I want to remove Root open and close tag (<Root> and </Root>), can anyone
> tell how?


With the above structure it is easy, simply replace the DocumentElement
with the AutoData element:

Dim Xml_Document as System.Xml.XmlDocument = New System.Xml.XmlDocument()

Xml_Document.Load("file.xml")

Xml_Document.ReplaceChild(Xml_Document.SelectSingleNode("Root/AutoData"),
Xml_Document.DocumentElement)

Xml_Document.Save("file2.xml")


--

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/
Author
9 Nov 2006 3:21 PM
martin1
Thank you for yuor quick response! Martin

I will post 3 more xml questions in couple of minutes later, can you take a
look at it?

Thanks for your time.

Show quoteHide quote
"Martin Honnen" wrote:

> martin1 wrote:
>
> > <Root>
> > <AutoData>
> > <Table1>
> > <Data1>  10 </Data1>
> > <Data2>  20 </Data2>
> > <Data3>  40 </Data3>
> > <Table1>
> > <Table2>
> > <Data1>  10 </Data1>
> > <Data2>  20 </Data2>
> > <Data3>  40 </Data3>
> > <Table2>
> > </AutoData>
> > </Root>
> >
> > I want to remove Root open and close tag (<Root> and </Root>), can anyone
> > tell how?
>
>
> With the above structure it is easy, simply replace the DocumentElement
> with the AutoData element:
>
> Dim Xml_Document as System.Xml.XmlDocument = New System.Xml.XmlDocument()
>
> Xml_Document.Load("file.xml")
>
> Xml_Document.ReplaceChild(Xml_Document.SelectSingleNode("Root/AutoData"),
> Xml_Document.DocumentElement)
>
> Xml_Document.Save("file2.xml")
>
>
> --
>
>     Martin Honnen --- MVP XML
>     http://JavaScript.FAQTs.com/
>
Author
9 Nov 2006 4:19 PM
rowe_newsgroups
Perhaps you should find an online tuturial, search these newsgroups, or
even visit a library or bookstore and do a little research yourself?

I not trying to be mean here, but when people see you posting 5
questions within two hours, they are very likely to ignore your posts
completely. All I'm asking is for you to please make an effort to find
the answers before you post to a newsgroup. You will learn much more
this way!

Thanks,

Seth Rowe


martin1 wrote:
Show quoteHide quote
> Thank you for yuor quick response! Martin
>
> I will post 3 more xml questions in couple of minutes later, can you take a
> look at it?
>
> Thanks for your time.
>
> "Martin Honnen" wrote:
>
> > martin1 wrote:
> >
> > > <Root>
> > > <AutoData>
> > > <Table1>
> > > <Data1>  10 </Data1>
> > > <Data2>  20 </Data2>
> > > <Data3>  40 </Data3>
> > > <Table1>
> > > <Table2>
> > > <Data1>  10 </Data1>
> > > <Data2>  20 </Data2>
> > > <Data3>  40 </Data3>
> > > <Table2>
> > > </AutoData>
> > > </Root>
> > >
> > > I want to remove Root open and close tag (<Root> and </Root>), can anyone
> > > tell how?
> >
> >
> > With the above structure it is easy, simply replace the DocumentElement
> > with the AutoData element:
> >
> > Dim Xml_Document as System.Xml.XmlDocument = New System.Xml.XmlDocument()
> >
> > Xml_Document.Load("file.xml")
> >
> > Xml_Document.ReplaceChild(Xml_Document.SelectSingleNode("Root/AutoData"),
> > Xml_Document.DocumentElement)
> >
> > Xml_Document.Save("file2.xml")
> >
> >
> > --
> >
> >     Martin Honnen --- MVP XML
> >     http://JavaScript.FAQTs.com/
> >