0

[Excuse me for my English] I have the following xml document. The document has a lot of nesting and I just need a field. Therefore, I think it is unnecessary to create many objects just to get a some fields.

<cac:root>    
   <cac:a>
    <cbc:b>
     <ccc:c>
       ....
        <czc:z>
          here i'm
        </czc:z>
       ....
     </ccc:c>   
    </cbc:b>
   </cac:a>

   <cac:x>
     some value 1
   </cac:x>

   <cbc:y>
     some value 2
   </cbc:y>
</cac:root>  

I'm mapping it in the following way

Some_object objectx = (some_object)serializer.Deserialize(some_reader);

...

[Serializable()]
[XmlRoot(ElementName = "root", Namespace = cac)]
public class Invoice_DTO
{
    public const string cac = "some_namespace A";
    public const string cbc = "some_namespace B";
    public const string ccc = "some_namespace C"; 
    ....


    [XmlElement(ElementName = "x", Namespace = cac)]
    public string element_x { get; set; }

    [XmlElement(ElementName = "y", Namespace = cbc)]
    public string element_y { get; set; }

    [XmlElement(ElementName = "z", ?????)]
    public string element_z { get; set; }
 }

please, any idea?

  • 1
    You probably don't want to use deserialization, but the lower-level XML APIs, e.g. https://stackoverflow.com/a/14110246/51685 – AKX Jun 12 '19 at 17:33
  • Possible duplicate of [Reading specific XML elements from XML file](https://stackoverflow.com/questions/14110212/reading-specific-xml-elements-from-xml-file) – Dour High Arch Jun 12 '19 at 17:38
  • 1
    Would you consider using a XPath query to get this value instead of serialization? – tgolisch Jun 12 '19 at 18:07

0 Answers0