mail-archives/mono-list/2003-October/016141.html

99 строки
3.1 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Mono-list] Modify XML Docs
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:miguel%40ximian.com">
<META NAME="robots" CONTENT="index,nofollow">
<LINK REL="Previous" HREF="016140.html">
<LINK REL="Next" HREF="016142.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Mono-list] Modify XML Docs
</H1>
<B>Miguel de Icaza
</B>
<A HREF="mailto:miguel%40ximian.com"
TITLE="[Mono-list] Modify XML Docs">miguel@ximian.com
</A><BR>
<I>05 Oct 2003 14:38:24 -0400</I>
<P><UL>
<LI> Previous message: <A HREF="016140.html">[Mono-list] Modify XML Docs
</A></li>
<LI> Next message: <A HREF="016142.html">[Mono-list] Modify XML Docs
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#16141">[ date ]</a>
<a href="thread.html#16141">[ thread ]</a>
<a href="subject.html#16141">[ subject ]</a>
<a href="author.html#16141">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>Hello,
&gt;<i> Im creating an app (mBloggy, to post 'posts' to a blog), however I'm
</I>&gt;<i> going to use a xml file to save the user configuration (the blogs).
</I>&gt;<i> Today I can write (JUST new files), read it and identify some parts, but
</I>&gt;<i> I dont undestand what the inet says about modifying xml files, so How
</I>&gt;<i> can I modify an xml file? to modify nodes and remove elements, for
</I>&gt;<i> example:
</I>&gt;<i>
</I>&gt;<i> &lt;mbloggy&gt;
</I>&gt;<i> &lt;account&gt;
</I>&gt;<i> &lt;username&gt;Pablo&lt;/username&gt;
</I>&gt;<i> &lt;password&gt;Crypted&lt;/password&gt;
</I>&gt;<i> &lt;identifier&gt;Personal WebSite&lt;/identifier&gt;
</I>&gt;<i> &lt;url&gt;<A HREF="http://pablo.com.mx/xmlrpc.php</url">http://pablo.com.mx/xmlrpc.php&lt;/url</A>&gt;
</I>&gt;<i> &lt;/account&gt;
</I>&gt;<i> &lt;account&gt;
</I>&gt;<i> ... the same..
</I>&gt;<i> &lt;/account&gt;
</I>&gt;<i> &lt;/mbloggy&gt;
</I>
This sounds like a prime candidate for XmlSerialization, use:
public class mbloggy {
public Account [] accounts;
}
public class account {
public string username;
public string password;
public string identifier;
public string url;
}
mbloggy m = new mbloggy ();
account a = new Account;
m.accounts = new Account [1];
m.accounts [0] = a;
a.username = &quot;Miguel&quot;;
a.identifier = &quot;...&quot;;
XmlSerializer s = new XmlSerializer (typeof (mbloggy));
s.Serialize (Console.Out, m);
Miguel
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI> Previous message: <A HREF="016140.html">[Mono-list] Modify XML Docs
</A></li>
<LI> Next message: <A HREF="016142.html">[Mono-list] Modify XML Docs
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#16141">[ date ]</a>
<a href="thread.html#16141">[ thread ]</a>
<a href="subject.html#16141">[ subject ]</a>
<a href="author.html#16141">[ author ]</a>
</LI>
</UL>
</body></html>