473,669 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Reading in VB.net

BiT
Hello

i'm tryin` to read xml elements from NZB type file (Link to nzb sample:
http://en.wikipedia.org/wiki/Nzb)

I worte this code but it dosen't find any elements (I need to get the
message ID)
Sub NZBToMsgID(ByVa l _FileLnk As String, ByVal msgIDbox As ComboBox)

Dim m_xmld As XmlDocument

Dim m_nodelist As XmlNodeList

Dim m_node As XmlNode

'Create the XML Document

m_xmld = New XmlDocument()

'Load the Xml file

m_xmld.Load(_Fi leLnk)

'Get the list of name nodes

m_nodelist = m_xmld.SelectNo des("/nzb/file/segments/segment")

'Loop through the nodes

For Each m_node In m_nodelist

msgIDBox.Items. Add(m_node.Chil dNodes.Item(0). InnerText)

Next

End Sub
thanks
May 28 '07 #1
8 6779
BiT wrote:
i'm tryin` to read xml elements from NZB type file (Link to nzb sample:
http://en.wikipedia.org/wiki/Nzb)

I worte this code but it dosen't find any elements (I need to get the
message ID)
Sub NZBToMsgID(ByVa l _FileLnk As String, ByVal msgIDbox As ComboBox)

Dim m_xmld As XmlDocument

Dim m_nodelist As XmlNodeList

Dim m_node As XmlNode

'Create the XML Document

m_xmld = New XmlDocument()

'Load the Xml file

m_xmld.Load(_Fi leLnk)

'Get the list of name nodes

m_nodelist = m_xmld.SelectNo des("/nzb/file/segments/segment")
You need to bind a prefix to the default namespace e.g.
Dim namespaceManage r As XmlNamespaceMan ager = New
XmlNamespaceMan ager(m_xmld.Nam eTable)
namespaceManage r.AddNamespace( "pf",
"http://www.newzbin.com/DTD/2003/nzb")
m_nodelist = m_xmld.SelectNo des("/pf:nzb/pf:file/pf:segments/pf:segment")
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 28 '07 #2
BiT
i've tried it but i get error message:
"Namespace Manager or XsltContext needed. This query has a prefix, variable,
or user-defined function."

here's the code:

Sub NZBToMsgID(ByVa l _FileLnk As String)
Dim m_xmld As XmlDocument

Dim m_nodelist As XmlNodeList

Dim m_node As XmlNode

'Create the XML Document

m_xmld = New XmlDocument()

'Load the Xml file

m_xmld.Load(_Fi leLnk)

Dim namespaceManage r As XmlNamespaceMan ager = New
XmlNamespaceMan ager(m_xmld.Nam eTable)

namespaceManage r.AddNamespace( "pf", "http://www.newzbin.com/DTD/2003/nzb")

m_nodelist = m_xmld.SelectNo des("/pf:nzb/pf:file/pf:segments/pf:segment")

'Loop through the nodes

For Each m_node In m_nodelist

Dim a = m_node.ChildNod es.Item(0).Inne rText

Next

End Sub

May 28 '07 #3
BiT wrote:
i've tried it but i get error message:
"Namespace Manager or XsltContext needed. This query has a prefix,
variable, or user-defined function."
My bad, forgot to change
m_nodelist = m_xmld.SelectNo des("/pf:nzb/pf:file/pf:segments/pf:segment")
to
m_nodelist =
m_xmld.SelectNo des("/pf:nzb/pf:file/pf:segments/pf:segment",
namespaceManage r)

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 28 '07 #4
BiT
ok it's work thank you.

i tried to play with it and understand how this namespace work, but i didn't
=>
can u explain little on this namespace and for example how can i retrive the
segment size or the file name

thank you again

May 28 '07 #5
Bit

Did you use the XMLtextreader instead of the more Internet way with the
Load.

http://msdn2.microsoft.com/en-us/lib...extreader.aspx

Cor
"BiT" <sh********@wal la.comschreef in bericht
news:9I******** *************@g iganews.com...
Hello

i'm tryin` to read xml elements from NZB type file (Link to nzb sample:
http://en.wikipedia.org/wiki/Nzb)

I worte this code but it dosen't find any elements (I need to get the
message ID)
Sub NZBToMsgID(ByVa l _FileLnk As String, ByVal msgIDbox As ComboBox)

Dim m_xmld As XmlDocument

Dim m_nodelist As XmlNodeList

Dim m_node As XmlNode

'Create the XML Document

m_xmld = New XmlDocument()

'Load the Xml file

m_xmld.Load(_Fi leLnk)

'Get the list of name nodes

m_nodelist = m_xmld.SelectNo des("/nzb/file/segments/segment")

'Loop through the nodes

For Each m_node In m_nodelist

msgIDBox.Items. Add(m_node.Chil dNodes.Item(0). InnerText)

Next

End Sub
thanks


May 29 '07 #6
BiT
i tried use the XMLtextreader but still i don't understand how to navigate
in such xml file with namesapces

thanks

May 29 '07 #7
BiT wrote:
i tried to play with it and understand how this namespace work, but i
didn't =>
can u explain little on this namespace and for example how can i retrive
the segment size or the file name
If you have an XML document starting like this:

<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
<file subject="Linux Debian-3.1r5-i386-binary- CD1 Lucky Strike.par2
(1/1)"
date="117505876 5" poster="Ye**@po wer-post.org (Lucky Strike)">
<groups>
<group>alt.bina ries.cd.image.l inux</group>
</groups>
<segments>
<segment bytes="423495"
number="1">b5** *************** *********@news. usenext.de</segment>

then the root element nzb has a default namespace declaration
xmlns="http://www.newzbin.com/DTD/2003/nzb"
which applies to the root element and all its descendant elements
(unless a descendant had it own redeclaration of xmlns).
So this means that the nzb element and its descendant elements like
file, groups, group, segments, segment are in the namespace with name
http://www.newzbin.com/DTD/2003/nzb.

For XPath 1.0 to match such elements you need to bind a prefix to the
namespace URI and use that prefix in XPath expressions. That is
necessary as in an XPath expression
nzb
always matches nzb elements in _no_ namespace.

As for accessing a segment size in bytes, that is an attribute of the
element you can access like this:

For Each segment As XmlElement In
xmlDoc.SelectNo des("/pf:nzb/pf:file/pf:segments/pf:segment",
namespaceManage r)
Console.WriteLi ne(segment.Attr ibutes("bytes") .Value)
Next
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 29 '07 #8
Maybe should I have send you a sample of the nodereader

http://www.vb-tips.com/dbpages.aspx?...xmlnodereader#

Cor

"BiT" <sh********@wal la.comschreef in bericht
news:IZ******** *************** *******@giganew s.com...
>i tried use the XMLtextreader but still i don't understand how to navigate
in such xml file with namesapces

thanks

May 29 '07 #9

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

Similar topics

0
3580
by: Andy | last post by:
Hi, In the code below (not pretty I know but it's an early version :-P) I'm having problems reading the data object back in. If I move the reading code to immediately after the section where it is written ( commented out in code) then it reads in OK. However, when I move the code to the right place ( as shown here) it throws an IO exception. Both the Filter class and it's constituent class implement Serializable and it would seem the...
6
2401
by: Raymond Hettinger | last post by:
Found in a pamphlet at a pre-school: --------------------------------------- Reading improves vocabulary Reading raises cultural literacy through shared knowledge Reading develops writing skills Reading opens the mind to new ways of understanding Reading is fun Accordingly, I suggest the following works of literature:
4
3057
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
24
2749
by: Hendrik Schober | last post by:
Hi, I have a 'std::istream' and need to read its whole contents into a string. How can I do this? TIA; Schobi
19
10308
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much text is available until I have read it... which seems to imply that multiple reads of the input stream will be inevitable. Now I can correctly find the number of characters available by: |
4
9824
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile = tmpfile(); /* write into tmpFile */ ...
6
3785
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am trying to read a flatfile. In COBOL, my simple file layout and READ statement would look like below. Question: what is the standard, simple coding convention for reading in a flatfile - one record at a time?? SCANF does not work because of...
3
9506
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At the end of this message is the inflate method this is where I get stuck I know that I need a byte array but because I am decompressing a string I have no idea of how big the byte array will need to be in the end (the inflate and deflate methods...
9
5508
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex http://www.developersdex.com ***
4
3259
by: Gaijinco | last post by:
I had a file named nap.in which looks like this: 4 10:00 12:00 Lectures 12:00 13:00 Lunch, like always. 13:00 15:00 Boring lectures... 15:30 17:45 Reading 4 10:00 12:00 Lectures 12:00 13:00 Lunch, just lunch.
0
8383
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
8803
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
8587
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
8658
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
7407
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...
1
6210
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4206
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
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
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

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.