Serialize XPathNavigator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce Sandeman

    Serialize XPathNavigator

    Hi,
    Does anyone know how to serialize an XPathNavigator object?
    I have tried the following but it moans that the xpn does not have a parameterless
    constructor.

    XPathNavigator xpn = e.Source.Select SingleNode("/ns1:Invoice/ns1:InvoiceDeta il/ns1:Lines/ns1:Line/ns1:Matches/ns1:Match/ns1:SubLedger",
    this.NamespaceM anager);

    XmlSerializer x = new XmlSerializer(x pn.GetType());
    StringWriter tw = new StringWriter();

    x.Serialize(tw, xpn);
    StringBuilder sbldr = tw.GetStringBui lder();

    _tmpXML = sbldr.ToString( );

    thanks very much
    cheers
    Bruce


  • Marc Gravell

    #2
    Re: Serialize XPathNavigator

    What are you actually trying to do? Persist the underlying xml? In which
    case, .WriteSubtree(x mlWriter) may help.

    If not, can you clarify your intent?

    Marc


    Comment

    • Marc Gravell

      #3
      Re: Serialize XPathNavigator

      Or possibly just .OuterXml?

      Comment

      • Dave Sexton

        #4
        Re: Serialize XPathNavigator

        Hi Bruce,

        You won't be able to serialize XPathNavigator directly because it's not marked as Serializable.

        Why not just serialize the outer-xml of the particular node that you have selected in your example as a string?

        If there are particular settings in the XPathNavigator that you want to retain you could create a class that encapsulates those
        settings and mark it as [Serializable].

        --
        Dave Sexton

        "Bruce Sandeman" <bruce@deltasch emenospam.comno spamwrote in message news:e1c4af035e 98c8bb4bb6ecf85 e@news.altohiwa y.com...
        Hi,
        Does anyone know how to serialize an XPathNavigator object?
        I have tried the following but it moans that the xpn does not have a parameterless constructor.
        >
        XPathNavigator xpn =
        e.Source.Select SingleNode("/ns1:Invoice/ns1:InvoiceDeta il/ns1:Lines/ns1:Line/ns1:Matches/ns1:Match/ns1:SubLedger",
        this.NamespaceM anager);
        XmlSerializer x = new XmlSerializer(x pn.GetType());
        StringWriter tw = new StringWriter();
        >
        x.Serialize(tw, xpn);
        StringBuilder sbldr = tw.GetStringBui lder();
        >
        _tmpXML = sbldr.ToString( );
        >
        thanks very much
        cheers
        Bruce
        >
        >

        Comment

        • Bruce Sandeman

          #5
          Re: Serialize XPathNavigator

          Hi Dave,
          Thanks, I will give that a go.

          In response to Marc: I need the actual object to be serialized as it is a
          reference to a particular element within a repeating group and I have no
          way of knowing which instance I am in. (this is using InfoPath 2007).

          cheers
          Bruce

          Hi Bruce,
          >
          You won't be able to serialize XPathNavigator directly because it's
          not marked as Serializable.
          >
          Why not just serialize the outer-xml of the particular node that you
          have selected in your example as a string?
          >
          If there are particular settings in the XPathNavigator that you want
          to retain you could create a class that encapsulates those settings
          and mark it as [Serializable].
          >
          "Bruce Sandeman" <bruce@deltasch emenospam.comno spamwrote in message
          news:e1c4af035e 98c8bb4bb6ecf85 e@news.altohiwa y.com...
          >
          >Hi,
          >Does anyone know how to serialize an XPathNavigator object?
          >I have tried the following but it moans that the xpn does not have a
          >parameterles s constructor.
          >XPathNavigat or xpn =
          >>
          >e.Source.Selec tSingleNode("/ns1:Invoice/ns1:InvoiceDeta il/ns1:Lines/n
          >s1:Line/ns1:Matches/ns1:Match/ns1:SubLedger",
          >>
          >this.Namespace Manager);
          >>
          >XmlSerialize r x = new XmlSerializer(x pn.GetType());
          >>
          >StringWriter tw = new StringWriter();
          >>
          >x.Serialize(tw , xpn);
          >StringBuilde r sbldr = tw.GetStringBui lder();
          >_tmpXML = sbldr.ToString( );
          >>
          >thanks very much
          >cheers
          >Bruce

          Comment

          Working...