Click here to Skip to main content
15,912,977 members
Home / Discussions / XML / XSL
   

XML / XSL

 
QuestionXML Deserialization of Known Derived Classes Pin
Alexandre G13-Oct-05 21:19
Alexandre G13-Oct-05 21:19 
QuestionAdd new tag after every 5 elements Pin
Sushant_Mathur13-Oct-05 20:48
Sushant_Mathur13-Oct-05 20:48 
AnswerRe: Add new tag after every 5 elements Pin
niansah14-Oct-05 12:32
niansah14-Oct-05 12:32 
GeneralRe: Add new tag after every 5 elements Pin
Sushant_Mathur16-Oct-05 19:00
Sushant_Mathur16-Oct-05 19:00 
QuestionConvert OpenOffice XML to XHTML Pin
kylegreen13-Oct-05 9:02
kylegreen13-Oct-05 9:02 
QuestionWse X509 Certificate unaccessable through web client Pin
eni9ma12-Oct-05 14:17
eni9ma12-Oct-05 14:17 
AnswerRe: Wse X509 Certificate unaccessable through web client Pin
IsraelSep4-Aug-11 12:26
IsraelSep4-Aug-11 12:26 
QuestionXML serialized Parent/child output format?? Pin
PhrankBooth12-Oct-05 5:38
PhrankBooth12-Oct-05 5:38 
Hello,

The code below gives me this XML output(replaced brackets with dashes to show in forum):
--MethodList xmlns:xsd="http://www.w3.org/2001/XMLSchema"--
--xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--
--Method name="TestMethod" /--
--Param name="Param1" value="ParamValue"/--
--Param name="Param2" value="ParamValue" /--
--/MethodList--

But I'd like this:

--MethodList xmlns:xsd="http://www.w3.org/2001/XMLSchema"--
--xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--
--Method name="TestMethod" /--
--Param name="Param1" value="ParamValue"/--
--Param name="Param2" value="ParamValue" /--
--/Method
--/MethodList--

Basically I need to set the Param element as a child of the Method Element. Not having any luck. I'm new to XML.

Any ideas greatly appreciated? Thank you in advance!

This is the full code:

using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

[XmlRoot("MethodList")]
public class MethodList
{
private ArrayList aMethodList;
private ArrayList aParamList;

public MethodList()
{
aMethodList = new ArrayList();
aParamList = new ArrayList();
}

[XmlElement("Method")]
public Method[] Methods
{
get
{
Method[] aMthds = new Method[ aMethodList.Count ];
aMethodList.CopyTo( aMthds );
return aMthds;

}
set
{
if( value == null ) return;
Method[] aMthds = (Method[])value;
aMethodList.Clear();
foreach( Method aMthd in aMthds )
aMethodList.Add( aMthd );
}
}

[XmlElement("Param")]
public Param[] Params
{
get
{
Param[] aParms = new Param[ aParamList.Count ];
aParamList.CopyTo( aParms );
return aParms;

}
set
{
if( value == null ) return;
Param[] aParms = (Param[])value;
aParamList.Clear();
foreach( Param aParm in aParms )
aParamList.Add( aParm );
}
}

public int AddParam( Param aParm )
{
return aParamList.Add( aParm );
}

public int AddMthd( Method aMthd )
{
return aMethodList.Add( aMthd );
}


public void InsertMethod()
{

MethodList aMthdLst = new MethodList();

aMthdLst.AddMthd( new Method( "TestMethod"));
aMthdLst.AddParam(new Param("Param1","ParamValue"));
aMthdLst.AddParam(new Param("Param2","ParamValue"));

// Serialization
XmlSerializer s = new XmlSerializer( typeof( MethodList ) );
TextWriter w = new StreamWriter( "list.xml" );
s.Serialize( w, aMthdLst );
w.Close();

// Deserialization
MethodList newList;
TextReader r = new StreamReader( "list.xml" );
newList = (MethodList)s.Deserialize( r );
r.Close();
}

}

// Method list
public class Method
{
[XmlAttribute("name")] public string name;
// [XmlElement("param")] public Param param;


public Method()
{
}

public Method( string theName)
{
name = theName;
}
}


//Params

public class Param
{
[XmlAttribute("name")] public string name;
[XmlAttribute("value")] public string pValue;

public Param()
{
}

public Param( string theName, string theValue )
{
name = theName;
pValue = theValue;

}
}

PhrankBooth

-- modified at 11:44 Wednesday 12th October, 2005
AnswerRe: XML serialized Parent/child output format?? Pin
PhrankBooth12-Oct-05 10:15
PhrankBooth12-Oct-05 10:15 
Questionremove soap envelop and create html outptu Pin
Stephini10-Oct-05 16:58
sussStephini10-Oct-05 16:58 
Questionplease help..About XML- RPC Pin
prashantarun9-Oct-05 20:44
prashantarun9-Oct-05 20:44 
AnswerRe: please help..About XML- RPC Pin
Marc Soleda10-Oct-05 0:11
Marc Soleda10-Oct-05 0:11 
GeneralRe: please help..About XML- RPC Pin
prashantarun10-Oct-05 20:37
prashantarun10-Oct-05 20:37 
GeneralRe: please help..About XML- RPC Pin
Marc Soleda10-Oct-05 22:38
Marc Soleda10-Oct-05 22:38 
QuestionHELP FOR NEWBIE! Pin
dgap7-Oct-05 13:43
dgap7-Oct-05 13:43 
QuestionnoXPath and multi-part element question Pin
RB@Emphasys5-Oct-05 8:37
RB@Emphasys5-Oct-05 8:37 
AnswerRe: noXPath and multi-part element question Pin
RB@Emphasys5-Oct-05 8:42
RB@Emphasys5-Oct-05 8:42 
QuestionHow create image with SVG and JavaScript? Pin
Anonymous4-Oct-05 1:08
Anonymous4-Oct-05 1:08 
QuestionLINKING OF XML AND WML Pin
ravi raman3-Oct-05 5:55
ravi raman3-Oct-05 5:55 
QuestionNesting Invalid HTML in XML Docs Pin
callingshotgun28-Sep-05 18:28
callingshotgun28-Sep-05 18:28 
AnswerRe: Nesting Invalid HTML in XML Docs Pin
jkersch29-Sep-05 4:08
jkersch29-Sep-05 4:08 
GeneralRe: Nesting Invalid HTML in XML Docs Pin
callingshotgun29-Sep-05 8:24
callingshotgun29-Sep-05 8:24 
Questionxalan? Pin
Member 194743127-Sep-05 2:32
Member 194743127-Sep-05 2:32 
AnswerRe: xalan? Pin
Christian Graus27-Sep-05 3:17
protectorChristian Graus27-Sep-05 3:17 
GeneralRe: xalan? Pin
Member 194743127-Sep-05 3:29
Member 194743127-Sep-05 3:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.