473,804 Members | 3,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath from String

Does anyone have an example on using an XPath statement (in VB.NET) where the
source XML document is NOT a file, but a 'text' value from SQL Server?
Jan 16 '06 #1
8 6236
Load the text file into an XMLDocument and use XPath from there?
"Joe Pannone" <Jo********@dis cussions.micros oft.com> wrote in message
news:53******** *************** ***********@mic rosoft.com...
Does anyone have an example on using an XPath statement (in VB.NET) where
the
source XML document is NOT a file, but a 'text' value from SQL Server?

Jan 16 '06 #2
Its NOT a text file, its a 'text' value in a SQL Server table.

I have a (SQL Server 2005) table with a field (defined as TEXT) that contains
an XML document. In VB.NET (VS 2005) I need to get this xml document and
perform XPath statements on it. When I get the XML document and convert it
to a string I loose part of the document.

Dim xmltext As New System.Text.Str ingBuilder
Dim strReader As StringReader = New StringReader(xm ltext.ToString)
Dim reader As XmlTextReader = New XmlTextReader(s trReader)
Dim strSQL As New System.Text.Str ingBuilder

strSQL.Append(" SELECT msg as VAL from tblMessage WHERE ID=100")
'routine ExecSQLReturnVa l executes a SQL statements are returns VAL
xmltext.Append( ExecSQLReturnVa l(strSQL.ToStri ng))
strReader = New StringReader(xm ltext.ToString)
reader = New XmlTextReader(s trReader)
docNav = New XPathDocument(r eader)
now 'xmltext' does not have the full XML document, it has been cut off

Scott, Do you have an example in VB.NET to load the text?

"Scott M." wrote:
Load the text file into an XMLDocument and use XPath from there?
"Joe Pannone" <Jo********@dis cussions.micros oft.com> wrote in message
news:53******** *************** ***********@mic rosoft.com...
Does anyone have an example on using an XPath statement (in VB.NET) where
the
source XML document is NOT a file, but a 'text' value from SQL Server?


Jan 16 '06 #3
Checkout my XPath examples:

http://weblogs.asp.net/sonukapoor/articles/159790.aspx

Sonu Kapoor
---
Posted via www.DotNetSlackers.com
Jan 16 '06 #4
Sonu, the examples on the site all use an actual XML file:

ds.ReadXml(Serv er.MapPath("fil e.xml"));
....

XPathDocument xmlDoc= new XPathDocument(S erver.MapPath(" categories.xml" ));
Does anyone have an example (preferably in VB.NET) when using XPath with an
XML document NOT from a file but from a SQL Table?


"Sonu Kapoor [MVP]" wrote:
Checkout my XPath examples:

http://weblogs.asp.net/sonukapoor/articles/159790.aspx

Sonu Kapoor
---
Posted via www.DotNetSlackers.com

Jan 16 '06 #5


Joe Pannone wrote:
Does anyone have an example on using an XPath statement (in VB.NET) where the
source XML document is NOT a file, but a 'text' value from SQL Server?


Here is a VB.NET example that reads the XML input from a .NET string
variable

Dim ExampleXML As String = "<gods><god>Kib o</god></gods>"
Dim Xml_Document As XPathDocument = _
New XPathDocument(N ew StringReader(Ex ampleXML))
Dim Navigator As XPathNavigator = Xml_Document.Cr eateNavigator()
Dim NodeIterator As XPathNodeIterat or = _
Navigator.Selec t("/gods/god")
While NodeIterator.Mo veNext()
Console.WriteLi ne(NodeIterator .Current.Value)
End While

If you have problems reading out text data from a data base into a
string variable then ask in a data base group.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 16 '06 #6
The fact that is coming from SQL is irrelevant. What you have is a string
of XML on your hands. Just use the LoadXML method of the XMLDocument object
to load it up.
"Joe Pannone" <Jo********@dis cussions.micros oft.com> wrote in message
news:06******** *************** ***********@mic rosoft.com...
Sonu, the examples on the site all use an actual XML file:

ds.ReadXml(Serv er.MapPath("fil e.xml"));
...

XPathDocument xmlDoc= new XPathDocument(S erver.MapPath(" categories.xml" ));
Does anyone have an example (preferably in VB.NET) when using XPath with
an
XML document NOT from a file but from a SQL Table?


"Sonu Kapoor [MVP]" wrote:
Checkout my XPath examples:

http://weblogs.asp.net/sonukapoor/articles/159790.aspx

Sonu Kapoor
---
Posted via www.DotNetSlackers.com

Jan 16 '06 #7
Dim doc As XmlDocument = New XmlDocument()
doc.LoadXM(refe r to the SQL text here)


"Joe Pannone" <Jo********@dis cussions.micros oft.com> wrote in message
news:48******** *************** ***********@mic rosoft.com...
Its NOT a text file, its a 'text' value in a SQL Server table.

I have a (SQL Server 2005) table with a field (defined as TEXT) that
contains
an XML document. In VB.NET (VS 2005) I need to get this xml document and
perform XPath statements on it. When I get the XML document and convert
it
to a string I loose part of the document.

Dim xmltext As New System.Text.Str ingBuilder
Dim strReader As StringReader = New StringReader(xm ltext.ToString)
Dim reader As XmlTextReader = New XmlTextReader(s trReader)
Dim strSQL As New System.Text.Str ingBuilder

strSQL.Append(" SELECT msg as VAL from tblMessage WHERE ID=100")
'routine ExecSQLReturnVa l executes a SQL statements are returns VAL
xmltext.Append( ExecSQLReturnVa l(strSQL.ToStri ng))
strReader = New StringReader(xm ltext.ToString)
reader = New XmlTextReader(s trReader)
docNav = New XPathDocument(r eader)
now 'xmltext' does not have the full XML document, it has been cut off

Scott, Do you have an example in VB.NET to load the text?

"Scott M." wrote:
Load the text file into an XMLDocument and use XPath from there?
"Joe Pannone" <Jo********@dis cussions.micros oft.com> wrote in message
news:53******** *************** ***********@mic rosoft.com...
> Does anyone have an example on using an XPath statement (in VB.NET)
> where
> the
> source XML document is NOT a file, but a 'text' value from SQL Server?


Jan 16 '06 #8
A System.XML.XMLD ocument object has 2 methods for loading it up with XML.

XMLDocument.Loa d(xmlTextFile)
XMLDocument.Loa dXML(xmlString)

Use the second one and then use standard XPath for parsing.

http://msdn.microsoft.com/library/de...adxmltopic.asp

"Joe Pannone" <Jo********@dis cussions.micros oft.com> wrote in message
news:48******** *************** ***********@mic rosoft.com...
Its NOT a text file, its a 'text' value in a SQL Server table.

I have a (SQL Server 2005) table with a field (defined as TEXT) that
contains
an XML document. In VB.NET (VS 2005) I need to get this xml document and
perform XPath statements on it. When I get the XML document and convert
it
to a string I loose part of the document.

Dim xmltext As New System.Text.Str ingBuilder
Dim strReader As StringReader = New StringReader(xm ltext.ToString)
Dim reader As XmlTextReader = New XmlTextReader(s trReader)
Dim strSQL As New System.Text.Str ingBuilder

strSQL.Append(" SELECT msg as VAL from tblMessage WHERE ID=100")
'routine ExecSQLReturnVa l executes a SQL statements are returns VAL
xmltext.Append( ExecSQLReturnVa l(strSQL.ToStri ng))
strReader = New StringReader(xm ltext.ToString)
reader = New XmlTextReader(s trReader)
docNav = New XPathDocument(r eader)
now 'xmltext' does not have the full XML document, it has been cut off

Scott, Do you have an example in VB.NET to load the text?

"Scott M." wrote:
Load the text file into an XMLDocument and use XPath from there?
"Joe Pannone" <Jo********@dis cussions.micros oft.com> wrote in message
news:53******** *************** ***********@mic rosoft.com...
> Does anyone have an example on using an XPath statement (in VB.NET)
> where
> the
> source XML document is NOT a file, but a 'text' value from SQL Server?


Jan 16 '06 #9

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

Similar topics

0
1824
by: bdinmstig | last post by:
I am building various framework components for my team to use in development, and one of those components is a Facade for reading/writing user preferences. The idea is that preference settings are stored in a free-format XML document (in memory for the life of the session) and persisted to a database (as free text) on exit. I have taught my developers the basics of XPath, however I don't want to have to review XMLDOM code all over the...
1
6827
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
1
5494
by: kurt hansen | last post by:
hi I thought that this would be easy, but maybe not so much. I want to: pass an xpath expression and a string value to a stylesheet and copy the source xml document, changing the value of the node described by the xpath expression, to the new value.
5
4214
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple values in the where clause as below
18
7740
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr); System.out.println(xp.evaluate(new InputSource(new FileInputStream("a.xml"))));
9
2156
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example from a program we have where xpath can be entered in two parts so we have to be able
5
7937
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
3
4980
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml version="1.0" encoding="utf-8" ?> <thing xmlns="urn:thing-schema-v1"> <foo>foo thing</foo> <bar>bar thing</bar>
8
13202
by: Sven | last post by:
Dear all, I'm trying to extract data from HTML using XPath in Java. Unfortunately the text contents of nodes may contain <br/tags which are not correctly interpreted, at least not for me ;) A <pnode may contain this text: <p> Test1<br/>
0
9584
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
10082
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
9160
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
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
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.