Как Вы сериализируете строку как CDATA использование XmlSerializer?

У меня была эта проблема также. При рассмотрении различных .whl файлов. Я заметил, что не было никакой 32-разрядной версии tensorflow на python 3.7. В конце просто должен был установить Python 3.7 на 64 бита от здесь .

84
задан John Saunders 4 September 2009 в 19:50
поделиться

2 ответа

[XmlRoot("root")]
public class Sample1Xml
{
    internal Sample1Xml()
    {
    }

    [XmlElement("node")]
    public NodeType Node { get; set; }

    #region Nested type: NodeType

    public class NodeType
    {
        [XmlAttribute("attr1")]
        public string Attr1 { get; set; }

        [XmlAttribute("attr2")]
        public string Attr2 { get; set; }

        [XmlIgnore]
        public string Content { get; set; }

        [XmlText]
        public XmlNode[] CDataContent
        {
            get
            {
                var dummy = new XmlDocument();
                return new XmlNode[] {dummy.CreateCDataSection(Content)};
            }
            set
            {
                if (value == null)
                {
                    Content = null;
                    return;
                }

                if (value.Length != 1)
                {
                    throw new InvalidOperationException(
                        String.Format(
                            "Invalid array length {0}", value.Length));
                }

                Content = value[0].Value;
            }
        }
    }

    #endregion
}
62
ответ дан 24 November 2019 в 08:24
поделиться

В дополнение к способу, опубликованному Джоном Сондерсом, вы можете напрямую использовать XmlCDataSection в качестве типа, хотя это сводится почти к тому же:

private string _message;
[XmlElement("CDataElement")]
public XmlCDataSection Message
{  
    get 
    { 
        XmlDocument doc = new XmlDocument();
        return doc.CreateCDataSection( _message);
    }
    set
    {
        _message = value.Value;
    }
}
89
ответ дан 24 November 2019 в 08:24
поделиться
Другие вопросы по тегам:

Похожие вопросы: