Не можете десериализировать XML с несколькими пространствами имен?C#

Место общения программистов C#
Ответить
Anonymous
 Не можете десериализировать XML с несколькими пространствами имен?

Сообщение Anonymous »

Я создал набор классов с использованием xsd.exe.
Часть этих классов заключается в следующем < /p>

Код: Выделить всё

    [System.CodeDom.Compiler.GeneratedCodeAttribute("ISO20022 XSD", "6.0.0.0")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:iso:std:iso:20022:tech:xsd:head.002.001.01")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="urn:iso:std:iso:20022:tech:xsd:head.002.001.01", IsNullable=true)]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
[System.Runtime.InteropServices.GuidAttribute("1d6acf4f-69e6-497b-a248-186a0a4ac642")]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public partial class ISO20022PlusAnyPayload :  IISO20022PlusAnyPayload {
private object itemField = default(object);
private bool itemFieldSpecified = false;
public ISO20022PlusAnyPayload() {
}
/// 
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document), Namespace="urn:iso:std:iso:20022:tech:xsd:acmt.022.001.02")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document_EPC11506_2023_V10_SCT_InterPSP), Namespace="urn:iso:std:iso:20022:tech:xsd:camt.027.001.07")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document2), Namespace="urn:iso:std:iso:20022:tech:xsd:camt.029.001.09")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document3), Namespace="urn:iso:std:iso:20022:tech:xsd:camt.056.001.08")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document_EPC11506_2023_V10_SCT_InterPSP1), Namespace="urn:iso:std:iso:20022:tech:xsd:camt.087.001.06")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document4), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document5), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10CRA")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document6), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10CRB")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document7), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10CRG")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document8), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10CRT")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document9), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.002.001.10FKO")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document_EPC11406_2023_V10_SDD_Core_InterPSP), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.003.001.08")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document10), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.004.001.09")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document11), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.007.001.09")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document_EPC11506_2023_V10_SCT_InterPSP2), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08")]
[System.Xml.Serialization.XmlElementAttribute("Document", typeof(Document12), Namespace="urn:iso:std:iso:20022:tech:xsd:pacs.028.001.03")]
public object Item {
get {
return this.itemField;
}
set {
if (((value == default(object))
|| false)) {
this.itemField = default(object);
this.ItemSpecified = false;
}
else {
this.itemField = value;
this.ItemSpecified = true;
}
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool ItemSpecified {
get {
return (this.itemFieldSpecified || false);
}
set {
this.itemFieldSpecified = value;
}
}
< /code>
xml, который я пытаюсь остановить,  с л е д у ю щ е е   <   / p >   < b r   / > < c o d e > & l t ; ? x m l   v e r s i o n = ' 1 . 0 '   e n c o d i n g = ' U T F - 8 ' ? & g t ; < b r   / > & l t ; X c h g   x m l n s = & q u o t ; u r n : i s o : s t d : i s o : 2 0 0 2 2 : t e c h : x s d : h e a d . 0 0 2 . 0 0 1 . 0 1 & q u o t ; & g t ; < b r   / >         & l t ; P y l d D e s c & g t ; < b r   / >                 & l t ; P y l d D t l s & g t ; < b r   / >                         & l t ; P y l d I d r & g t ; F 2 1 1 5 9 0 0 0 0 0 1 1 5 7 7 & l t ; / P y l d I d r & g t ; < b r   / >                         & l t ; C r e D t A n d T m & g t ; 2 0 2 1 - 0 6 - 0 8 T 1 6 : 5 2 : 0 9 & l t ; / C r e D t A n d T m & g t ; < b r   / >                 & l t ; / P y l d D t l s & g t ; < b r   / >                 & l t ; A p p l S p c f c I n f & g t ; < b r   / >                         & l t ; S y s U s r & g t ; N I E & l t ; / S y s U s r & g t ; < b r   / >                         & l t ; T t l N b O f D o c s & g t ; 1 & l t ; / T t l N b O f D o c s & g t ; < b r   / >                 & l t ; / A p p l S p c f c I n f & g t ; < b r   / >                 & l t ; P y l d T p D t l s & g t ; < b r   / >                         & l t ; T p & g t ; I S O 2 0 0 2 2 C R A & l t ; / T p & g t ; < b r   / >                 & l t ; / P y l d T p D t l s & g t ; < b r   / >                 & l t ; M n f s t D t l s & g t ; < b r   / >                         & l t ; D o c T p & g t ; p a c s . 0 0 2 . 0 0 1 . 0 3 C R A & l t ; / D o c T p & g t ; < b r   / >                         & l t ; N b O f D o c s & g t ; 1 & l t ; / N b O f D o c s & g t ; < b r   / >                 & l t ; / M n f s t D t l s & g t ; < b r   / >         & l t ; / P y l d D e s c & g t ; < b r   / >         & l t ; P y l d & g t ; < b r   / >                 & l t ; A n y & g t ; < b r   / >                         & l t ; D o c u m e n t   x m l n s = & q u o t ; u r n : i s o : s t d : i s o : 2 0 0 2 2 : t e c h : x s d : p a c s . 0 0 2 . 0 0 1 . 0 3 C R A & q u o t ; & g t ; < b r   / >                                 & l t ; F I T o F I P m t S t s R p t & g t ; < b r   / >                                         & l t ; G r p H d r & g t ; < b r   / >                                                 & l t ; M s g I d & g t ; A B D I 2 1 1 5 9 0 0 0 0 0 1 2 4 8 3 & l t ; / M s g I d & g t ; < b r   / >                                                 & l t ; C r e D t T m & g t ; 2 0 2 1 - 0 6 - 0 8 T 1 6 : 5 2 : 1 0 & l t ; / C r e D t T m & g t ; < b r   / >                                         & l t ; / G r p H d r & g t ; < b r   / >                                         & l t ; O r g n l G r p I n f A n d S t s & g t ; < b r   / >                                                 & l t ; O r g n l M s g I d & g t ; A 0 4 0 8 0 6 X X X X U R D D 2 0 2 1 0 6 0 8 0 4 0 4 0 3 3 8 8 1 & l t ; / O r g n l M s g I d & g t ; < b r   / >                                                 & l t ; O r g n l M s g N m I d & g t ; p a c s . 0 0 3 . 0 0 1 . 0 2 & l t ; / O r g n l M s g N m I d & g t ; < b r   / >                                                 & l t ; O r g n l C r e D t T m & g t ; 2 0 2 1 - 0 6 - 0 5 T 0 4 : 0 0 : 0 5 & l t ; / O r g n l C r e D t T m & g t ; < b r   / >                                                 & l t ; O r g n l N b O f T x s & g t ; 3 & l t ; / O r g n l N b O f T x s & g t ; < b r   / >                                                 & l t ; O r g n l C t r l S u m & g t ; 1 0 1 5 0 . 0 1 & l t ; / O r g n l C t r l S u m & g t ; < b r   / >                                                 & l t ; G r p S t s & g t ; P A R T & l t ; / G r p S t s & g t ; < b r   / >                                                 & l t ; S t s R s n I n f & g t ; < b r   / >                                                         & l t ; R s n & g t ; < b r   / >                                                                 & l t ; P r t r y & g t ; R e j e c t e d   b y   C S M & l t ; / P r t r y & g t ; < b r   / >                                                         & l t ; / R s n & g t ; < b r   / >                                                         & l t ; A d d t l I n f & g t ; P y l d I d r   R E F 2 0 2 1 0 6 0 5 0 4 0 4 4 1 5 8 9 & l t ; / A d d t l I n f & g t ; < b r   / >                                                 & l t ; / S t s R s n I n f & g t ; < b r   / >                                                 & l t ; N b O f T x s P e r S t s & g t ; < b r   / >                                                         & l t ; D t l d N b O f T x s & g t ; 1 & l t ; / D t l d N b O f T x s & g t ; < b r   / >                                                         & l t ; D t l d S t s & g t ; R J C T & l t ; / D t l d S t s & g t ; < b r   / >                                                         & l t ; D t l d C t r l S u m & g t ; 1 5 0 . 0 0 & l t ; / D t l d C t r l S u m & g t ; < b r   / >                                         


T211580000013178
000052307XXECH210608P000AXPVVP 
202106050404077470000100003
RJCT




BPCEFRPPXXX




RB3 CRA17_invalidSettlementDate

NARR ABANDON


150.00
2021-06-08
2021-06-08




FR76ZZZ245313

SEPA






CLRG



SEPA


CORE

RCUR


P000AXP
2016-03-23


XXXXXXXXXXXX



FR7630004999999999999999999




BNPAFRPPXXX




NATXFRPPPAI



XXXXXXXXXXXX



FR76159309999999999999999999









Как видите, я намерен починить объект на основе его типа и/или (я не знаю) его пространства имен.public static NxT Deserialize(string data, bool xmlBom = false)
{
try
{
// remove version
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreWhitespace = true;
settings.CloseInput = true;

XmlSerializer xsSubmit = new XmlSerializer(typeof(NxT));
using (StreamReader stream = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(data)), Encoding.UTF8, xmlBom))
using (XmlReader reader = XmlReader.Create(stream, settings))
try
{
return (NxT)xsSubmit.Deserialize(reader);
}
catch (Exception ex)
{
}
}
}
catch (Exception ex)
{
}
return default(NxT);
}
< /code>
То, что происходит, является первой частью детериализированной, но элемент всегда остается нулевым (он должен переименовать документ и содержать оставшиеся данные), а не десериализован.>

Подробнее здесь: https://stackoverflow.com/questions/797 ... namespaces
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»