XML Text Node with an Attribute
Posted: Thu Sep 17, 2009 7:49 am
I'm working on taking some PHP classes and serializing them into XML. Rather than using arrays, I'm just using classes with public properties named the same as the XML nodes. This is working perfectly until I get to a XML text node that has an attribute attached to it. Here's an example:
Here's what my generated class looks like in my .NET simulator:
Here's what my PHP class looks like:
The value of currency comes through, but the actual value of Money does not. Anyone know how to do this? Changing XML schema's is not an option since it's set by our client.
Thanks.
Code: Select all
<Money currency="USD">40.0</Money>Code: Select all
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = true)]
public partial class Money
{
private string currencyField;
private string valueField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string currency
{
get
{
return this.currencyField;
}
set
{
this.currencyField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}
Code: Select all
class Money
{
public $Value;
public $currency;
public function __construct($value, $currency)
{
$this->Value = $value;
$this->currency = $currency;
}
}
Thanks.