473,802 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Namespaces

Lou
I have been working on something very simple for days now argh!
In VB6 it was 4 lines of code in 5 minutes!
In VB .NET how do i parse this simple xml documenet.
I cant get a reference to any of the nodes.

<?xml version="1.0" encoding="UTF-8" standalone="yes " ?>
- <cap:alert xmlns:cap="http ://www.incident.co m/cap/1.0">
<cap:identifier >NOAA-NWS-ALERTS Alabama
2007-02-16T10:03:56-05:00</cap:identifier>
<cap:sender>w-*************@n oaa.gov</cap:sender>
<cap:sent>200 7-02-16T10:03:56-05:00</cap:sent>
<cap:status>Act ual</cap:status>
<cap:msgType>Al ert</cap:msgType>
<cap:scope>Publ ic</cap:scope>
<cap:note>Curre nt Watches, Warnings and Advisories for Alabama Issued by
the National Weather Service</cap:note>
</cap:alert>
Feb 16 '07 #1
2 1950
Lou wrote:
In VB .NET how do i parse this simple xml documenet.
<?xml version="1.0" encoding="UTF-8" standalone="yes " ?>
- <cap:alert xmlns:cap="http ://www.incident.co m/cap/1.0">
<cap:identifier >NOAA-NWS-ALERTS Alabama
2007-02-16T10:03:56-05:00</cap:identifier>
<cap:sender>w-*************@n oaa.gov</cap:sender>
<cap:sent>200 7-02-16T10:03:56-05:00</cap:sent>
<cap:status>Act ual</cap:status>
<cap:msgType>Al ert</cap:msgType>
<cap:scope>Publ ic</cap:scope>
<cap:note>Curre nt Watches, Warnings and Advisories for Alabama Issued by
the National Weather Service</cap:note>
</cap:alert>
..NET has several ways to parse XML, one is XPathDocument/XPathNavigator

Imports System
Imports System.Xml
Imports System.Xml.XPat h

Module Module1

Sub Main()
Dim Navigator As XPathNavigator = New
XPathDocument(" XMLFile1.xml"). CreateNavigator ()
Dim NodeIterator As XPathNodeIterat or = Navigator.Selec t("*/*")
While NodeIterator.Mo veNext()
Console.WriteLi ne("Element name: ""{0}"", content:
""{1}""", NodeIterator.Cu rrent.LocalName , NodeIterator.Cu rrent.Value)
End While
End Sub

End Module

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 16 '07 #2
On Feb 16, 9:13 am, "Lou" <lou.gar...@com cast.netwrote:
I have been working on something very simple for days now argh!
In VB6 it was 4 lines of code in 5 minutes!
In VB .NET how do i parse this simple xml documenet.
I cant get a reference to any of the nodes.

<?xml version="1.0" encoding="UTF-8" standalone="yes " ?>
- <cap:alert xmlns:cap="http ://www.incident.co m/cap/1.0">
<cap:identifier >NOAA-NWS-ALERTS Alabama
2007-02-16T10:03:56-05:00</cap:identifier>
<cap:sender>w-nws.webmas...@n oaa.gov</cap:sender>
<cap:sent>200 7-02-16T10:03:56-05:00</cap:sent>
<cap:status>Act ual</cap:status>
<cap:msgType>Al ert</cap:msgType>
<cap:scope>Publ ic</cap:scope>
<cap:note>Curre nt Watches, Warnings and Advisories for Alabama Issued by
the National Weather Service</cap:note>
</cap:alert>
This would be a quick way to grab those individual node values of the
alert. If you want references to the actual nodes then change id,
sent, etc. variables to the type XmlNode and drop the .InnerXml in the
lines that assign the values.

Private Sub DoXmlStuff()

Dim x As New XmlDocument
Dim ns As XmlNamespaceMan ager
Dim id As String
Dim sent As String
Dim status As String
Dim msgType As String
Dim scope As String
Dim note As String

' Load the document
x.Load("whereve rMyFileIs.xml")
' Create the NameSpaceManage r
ns = New XmlNamespaceMan ager(x.NameTabl e)
ns.AddNamespace ("cap", "http://www.incident.co m/cap/1.0")
id = x.SelectSingleN ode("//cap:alert", ns).InnerXml
sent = x.SelectSingleN ode("//cap:sent", ns).InnerXml
status = x.SelectSingleN ode("//cap:status", ns).InnerXml
msgType = x.SelectSingleN ode("//cap:msgType", ns).InnerXml
scope = x.SelectSingleN ode("//cap:scope", ns).InnerXml
note = x.SelectSingleN ode("//cap:note", ns).InnerXml

Dim sOutput As String = String.Format(" ID: {0} Sent: {1}
Status: {2} MsgType: {3} Scope: {4} Note: {5}", id, sent, status,
msgType, scope, note)

MsgBox(sOutput)

End Sub

Feb 16 '07 #3

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

Similar topics

18
3054
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of a single collections type, I should be proposing a new "namespaces" module instead. Some of my reasons: (1) Namespace is feeling less and less like a collection to me. Even though it's still intended as a data-only structure, the use cases...
24
3534
by: Marcin Vorbrodt | last post by:
Here is an example of my code: //Header file #include <vector> using std::vector; namespace Revelation { // class definitions, etc... // class members are of type std::vector }
2
1594
by: Mike Morse | last post by:
What see sample that show xs:element where the xs namespace = http://www.w3.org/2001/XMLSchema However, I see another example with xsi: where xsi = http://www.w3.org/2001/XMLSchema-instance What's the difference here? Are there right and wrong namespaces? Is there a global list of the ones to use? Does the namespace even need to point at http://www.w3.org.....? Or is this just the accepted way?
3
2323
by: Jim Heavey | last post by:
Trying to get the hang of Namespaces. I have primarly developed in VB and am transitioning to C# and the .Net Environment. I have worked a bit with Java as well in school about a year or so ago. NameSpaces and Java Packages are similar in nature? In the dot net world, you are not able to pick out (import) a particulare "class" within the namespace - just the entire namespace. Is that Right? In Java, I would carve out a place on my...
17
2078
by: clintonG | last post by:
Using 2.0 with Master Pages and a GlobalBaseClass for the content pages. I understand the easy part -- the hierarchical structure of a namespace naming convention -- but the 2.0 IDE does not write a signature for the developer and after getting a good start developing a 2.0 application I thought I should go through the code and start marking classes and with namespaces. I keep getting the following 'missing' error even when using a first...
11
1795
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I understand that you declare your intention to use a namespace within a page through the "Inherits" attribute. I know that using "Inherits" isn't absolutely necessary, it's just recommended so the developer doesn't have to type out the entire...
0
9699
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
9562
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
10305
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...
0
9115
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
7598
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
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
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
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
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.