473,395 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.com/cap/1.0">
<cap:identifier>NOAA-NWS-ALERTS Alabama
2007-02-16T10:03:56-05:00</cap:identifier>
<cap:sender>w-*************@noaa.gov</cap:sender>
<cap:sent>2007-02-16T10:03:56-05:00</cap:sent>
<cap:status>Actual</cap:status>
<cap:msgType>Alert</cap:msgType>
<cap:scope>Public</cap:scope>
<cap:note>Current Watches, Warnings and Advisories for Alabama Issued by
the National Weather Service</cap:note>
</cap:alert>
Feb 16 '07 #1
2 1926
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.com/cap/1.0">
<cap:identifier>NOAA-NWS-ALERTS Alabama
2007-02-16T10:03:56-05:00</cap:identifier>
<cap:sender>w-*************@noaa.gov</cap:sender>
<cap:sent>2007-02-16T10:03:56-05:00</cap:sent>
<cap:status>Actual</cap:status>
<cap:msgType>Alert</cap:msgType>
<cap:scope>Public</cap:scope>
<cap:note>Current 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.XPath

Module Module1

Sub Main()
Dim Navigator As XPathNavigator = New
XPathDocument("XMLFile1.xml").CreateNavigator()
Dim NodeIterator As XPathNodeIterator = Navigator.Select("*/*")
While NodeIterator.MoveNext()
Console.WriteLine("Element name: ""{0}"", content:
""{1}""", NodeIterator.Current.LocalName, NodeIterator.Current.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...@comcast.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.com/cap/1.0">
<cap:identifier>NOAA-NWS-ALERTS Alabama
2007-02-16T10:03:56-05:00</cap:identifier>
<cap:sender>w-nws.webmas...@noaa.gov</cap:sender>
<cap:sent>2007-02-16T10:03:56-05:00</cap:sent>
<cap:status>Actual</cap:status>
<cap:msgType>Alert</cap:msgType>
<cap:scope>Public</cap:scope>
<cap:note>Current 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 XmlNamespaceManager
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("whereverMyFileIs.xml")
' Create the NameSpaceManager
ns = New XmlNamespaceManager(x.NameTable)
ns.AddNamespace("cap", "http://www.incident.com/cap/1.0")
id = x.SelectSingleNode("//cap:alert", ns).InnerXml
sent = x.SelectSingleNode("//cap:sent", ns).InnerXml
status = x.SelectSingleNode("//cap:status", ns).InnerXml
msgType = x.SelectSingleNode("//cap:msgType", ns).InnerXml
scope = x.SelectSingleNode("//cap:scope", ns).InnerXml
note = x.SelectSingleNode("//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
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...
24
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
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 ...
3
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....
17
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...
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.