Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

adding a node in XML file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vicente García - 21 Aug 2006 11:15 GMT
hi,
I have a xml file as shown:

<?xml version="1.0" encoding="utf-8"?>
   <PIM>
       <fragments>
       </fragments>
   </PIM>
</xml>

I must add children in the fragments node such as:

<fragments>
   <element name="name1">hello</element>
   <element name="name2">hello 2</element>
   <element name="name3">hello 3</element>
    ....
<fragments>

The problem is that I am not be able to add children using XmlDocument,
XmlElement nor XmlNode...May anyone help me with this issue?

Thanks in advance
regards
Vadym Stetsyak - 21 Aug 2006 11:27 GMT
Hello, Vicente!

[skipped]

VG> The problem is that I am not be able to add children using XmlDocument,
VG> XmlElement nor XmlNode...May anyone help me with this issue?

What's the problem? Give code sample, where you're trying to add children node.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Vicente Garcia - 21 Aug 2006 11:47 GMT
Thanks for the reply Vadym

This is my snippet code:
...
XmlNode fragments = root.SelectSingleNode("fragments");  //now I am in
fragments
...//My problem is that I don't know how to declare the node element and I
didn't find that on the Web
fragments.AppendChildNode(node); //I must add nodes

Apologies if my explanation insn't enough good, This is because of my mother
tongue isn't English
Thanks a lot!

> Hello, Vicente!
>
[quoted text clipped - 10 lines]
> Regards, Vadym Stetsyak
> www: http://vadmyst.blogspot.com
Vadym Stetsyak - 21 Aug 2006 12:14 GMT
Hello, Vicente!

VG> This is my snippet code:
VG> ...
VG> XmlNode fragments = root.SelectSingleNode("fragments");  //now I am in
VG> fragments
VG> ...//My problem is that I don't know how to declare the node element
VG> and I didn't find that on the Web

//assume that we have XmlDocument xmlDoc

XmlElement newElement = xmlDoc.CreateElement("element");
newElment.SetAttribute("name", "nameXXX");
fragments.AppendChild(newElement );

VG> Apologies if my explanation insn't enough good, This is because of my
VG> mother tongue isn't English

You're not alone :8-)

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Vicente Garcia - 21 Aug 2006 12:26 GMT
Thanks a million!

I've just run it and it works fine :)
I was very confused because of the examples I found didn't serve

regards

> Hello, Vicente!
>
[quoted text clipped - 19 lines]
> Regards, Vadym Stetsyak
> www: http://vadmyst.blogspot.com
Jared - 21 Aug 2006 12:08 GMT
> hi,
> I have a xml file as shown:
[quoted text clipped - 20 lines]
> Thanks in advance
> regards

Vicente,
What technicial limitation prohibits you from using the XmlDocument object
to manipulate your doucment (other than the fact that this document is not
valid xml)?
Unless you can provide sound logical reasons and technical limitations there
isn't a solution for you here - only a hack.

The XmlDocument object conforms to the xml standards, unless you know
exactly what you are doing you should avoid the "I'm smarter than the
framework developers" approach to xml manipulation.  Don't take offence to
this either. I've seen way to many solvable problems that people just don't
take the time to fix correctly.  Some just apply a hack to get it working and
never go back.  This will cause more problems in the long run.  

<?xml version="1.0" encoding="utf-8"?>
    <PIM>
        <fragments>
        </fragments>
    </PIM>
</xml>  
<!-- </xml> is not valid -
The <?xml version="1.0" ?> is a processing instruction and is required for
all xml documents, it doesn't required any ending tag, let alone one that was
never defined.
Vicente García - 21 Aug 2006 12:56 GMT
hi Jared
I type the last </xml> but it isn't in my code, I didn't realize
I could use XmlDocument, in fact this is my intention but I didn't Know how
to use it in this situation because my code always failed, but now Vadim
shows me how to use it.

many thanks
regards

> Vicente,
> What technicial limitation prohibits you from using the XmlDocument object
[quoted text clipped - 24 lines]
> was
> never defined.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.