473,789 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Oct 11 '06 #1
4 4404
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
Oct 11 '06 #2
Or possibly just .OuterXml?

Oct 11 '06 #3
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" <br***@deltasch emenospam.comno spamwrote in message news:e1******** *************** *@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


Oct 11 '06 #4
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" <br***@deltasch emenospam.comno spamwrote in message
news:e1******** *************** *@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

Oct 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3378
by: Craig Pearson | last post by:
Hi My function receives an XPathNavigator object. From here I need to build a DataSet to load into SQL Server (using SQLXML adaptor). Does anyone have an idea on the most efficient way to convert the XPathNavigator into a DataSet? Here is what I have at the moment: void function DoSomething( string xmlSchemeFile, System.Xml.XPath.XPathNavigator nav ) {
7
3900
by: news.microsoft.com | last post by:
Hi, Is the compilation of XSLT, using XPathNavigator.Compile, only beneficial when the returned XPathExpression is cached? Next question, how do I cache the returned XPathExpression object? Should I programmatically cache it or is it automatically cached when the Compile method is called? Thanks
1
1746
by: Phil | last post by:
Is there an easy way to get the schema's data type for a XPathNavigator value? I need to be able to determine the data type for the xml value based off of an unknown schema and unknown xml file that is handed off to my code. I've been able to figure out how to get the data type by reading through a validating reader, but I can't seem to find an easy way to get this when using XPath expressions. The process I have is as follows: 1....
1
2167
by: Bruce Dunwiddie | last post by:
I'm trying to build a couple classes that would allow for writing xsl transforms against data that is not originally xml. I've got an xmlreader implementation that seems to work well. Based on some issues with it and transforms, I then wrapped it up in a custom xpathnavigator implementation. Everything works fine from the transform functionality perspective, but it's not scaling well to larger amounts of data, and I would like to find out...
7
4088
by: David Thielen | last post by:
Hi; Is there a way from an XPathNavigator object to get an xpath string that will, when used in a Select(xpath) on the underlying base/root XPathNavigator return the same XPathNavigator? In other words, I initially create an XPathNavigator for my entire xml document. To get an XPathNavigator object who's root is a given node in the original xml document, there is a unique xpath that will return that node. The unique xpath could have,...
12
3965
by: David Thielen | last post by:
Hi; I have an element: <space> </space> When I call SelectSingleNode() on it, the InnerXml is a 0 length String, not a String containing 1 space. Any ideas?
2
2897
by: JSheble | last post by:
I'm integrating with a customer application, and in their assembly, when I call a method it returns data to us as an XPathNavigator object. I can parse the various elements I need out of this object with no problem, but what I cannot seem to do is get at the actual XML string itself. For accountability, tracking, auditing, and logging, I need to save the XML as an XML file in an archive folder, but there doesn't seem to be any way of...
11
6467
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString); XPathNavigator nav = docNav.CreateNavigator(); XmlDocument doc = new XmlDocument(); doc.LoadXml("<DocumentData></DocumentData>"); XmlElement elem = doc.CreateElement(currentNodeName);
2
4543
by: =?Utf-8?B?Tm9yZW1hYw==?= | last post by:
Hi. Using VS2005, .NET 2.0. I have an xml document that I want to go through and set the values on attributes of elements. The elements are complex types defined in my schema (xsd) files. I can iterate the document and get my XmlType and XmlBaseType values just fine. However, as soon as I call SetValue to write to an attribute, the
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.