473,609 Members | 2,296 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem using default xml namespace and selectsignlenod e/selectnod

rrm
Hi

I am verifying a SLD implementation using xml, however I have som problem
using xpath and default namespaces in vb.net

Currently I have the following xml
<?xml version="1.0"?>
<StyledLayerDes criptor version="1.0.0"
xsi:schemaLocat ion="http://www.opengis.net/sld
http://schemas.opengis .net/sld/1.0.0/StyledLayerDesc riptor.xsd"
xmlns:sld="http ://www.opengis.net/sld" xmlns:ogc="http ://www.opengis.net/ogc"
xmlns:xlink="ht tp://www.w3.org/1999/xlink"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<Name>TestNam e</Name>
<Title>TestTitl e</Title>
<Abstract>TestA bstract</Abstract>
</StyledLayerDesc riptor>

and the following code to read it:
Dim writer As Xml.XmlTextWrit er = New Xml.XmlTextWrit er(file, Nothing)
doc.Load(file)
where file is the location of the xml and doc is a xmldocument objekt

I ask with:
Dim r As Xml.XmlNode = doc.SelectSingl eNode("/StyledLayerDesc riptor/Name")
Console.WriteLi ne("Name " & r.InnerXml)

The return value is nothing, any clue of why??? If I dont use default
namespace, then it can be found.

rrm
Aug 23 '06 #1
3 2371


rrm wrote:

Dim r As Xml.XmlNode = doc.SelectSingl eNode("/StyledLayerDesc riptor/Name")
The return value is nothing, any clue of why??? If I dont use default
namespace, then it can be found.
You need a namespace manager e.g.
Dim namespaceManage r As XmlNamespaceMan ager =_
new XmlNamespaceMan ager(doc.NameTa ble)
namespaceManage r.AddNamespace( "pf", "default namespace URI here")
then e.g.
doc.SelectSingl eNode("/pf:StyledLayerD escriptor/pf:Name",_
namespaceManage r)

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 23 '06 #2
rrm

Hi
You need a namespace manager e.g.
Dim namespaceManage r As XmlNamespaceMan ager =_
new XmlNamespaceMan ager(doc.NameTa ble)
namespaceManage r.AddNamespace( "pf", "default namespace URI here")
then e.g.
doc.SelectSingl eNode("/pf:StyledLayerD escriptor/pf:Name",_
namespaceManage r)
ok

I found an error in my posting: xmlns:sld=... should be xmlns=...
<StyledLayerDes criptor version="1.0.0"
xsi:schemaLocat ion="http://www.opengis.net/sld
http://schemas.opengis .net/sld/1.0.0/StyledLayerDesc riptor.xsd"
xmlns="http://www.opengis.net/sld" xmlns:ogc="http ://www.opengis.net/ogc"
xmlns:xlink="ht tp://www.w3.org/1999/xlink"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">

Would that help me to avoid using namespace "ns:" in selectsinglenod e???

Are there any different in the way dotnet 1 and dotnet 2 handles this??
Aug 24 '06 #3


rrm wrote:

I found an error in my posting: xmlns:sld=... should be xmlns=...
Would that help me to avoid using namespace "ns:" in selectsinglenod e???
You need to use a namespace manager if you want to select elements or
attributes in a namespace. An XPath (1.0) expression in the form of e.g.
element-name
only selects elements of that name in _no_ namespace. If your elements
are in a namespace then you need a namespace manager that binds a prefix
to the namespace URI and then you need to use that prefix in the XPath
expression e.g.
pf:element-name

See also "Namespaces in XPath Expressions" in
<http://msdn2.microsoft .com/en-us/library/d271ytdx.aspx>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 26 '06 #4

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

Similar topics

9
1726
by: SB | last post by:
Ok, very simple problem. I'm trying to update a value by calling a function using pass by reference, but it does not update the value. In short, the value I'm trying to update is balance, which is a private member of the class Account. I have a public function called getBalance(). I have another public function called deposit, which I pass the balance (by calling getBalance() using pass by reference) and a second value for the amount of...
4
1910
by: MrTang001 | last post by:
How I can fix this problem? I don't know why it alway prompted (first use this function). I have use newDollars, newCents... to access the base class member variable. And the member functions for Initialize() and Print(), is it function overloading? it already have this functions in the base class. Pls let me know what problem of its! Thx ------------------------------------------------------------------ Result
4
5835
by: Andreas Håkansson | last post by:
I have a price of XML that looks like this <Root> <SomeNode> ..... </SomeNode> <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> ... </Signature> </Root>
1
5801
by: Robert | last post by:
I am having a problem selecting nodes using the XMLnodelist Selectnodes using XPATH when I use XML SPY is successfully queries but when is use VB.net it comes up with nothing. Here is my code Dim nodess As XmlNode nodess = myNode.SelectSingleNode("//Web") If nodess Is Nothing Then SQLrw.Delete()
5
8218
by: Drew | last post by:
Assembly asm = Assembly.GetExecutingAssembly(); me = new Bitmap(asm.GetManifestResourceStream("me.gif")); I have used this before without any problem, but now I get: An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll Additional information: 'null' is not a valid value for 'stream'.
8
1301
by: Janaka | last post by:
I've recently set up IIS6 on a Windows 2003 server and am trying to migrate over my ASP.NET applications. I'm not using VS and my page's aspx file ususally contains something of the following: <%@ Page Src="Default.cs" Inherits="MyNamespace.Default" %> which worked fine previously. However now I keep getting the error The base type 'MyNamespace.Default' does not exist in the source file 'Default.cs'. Is this a problem with IIS 6?
1
1506
by: Michael | last post by:
Hello, I'm trying to implement sample I found on page templates, so I do not have to maintain "<html><head>..." on all my documents. But don't let that confuse you, this is an inheritance problem. Basically, I'm using VS.NET IDE for development, If I use the src="..." tag in the @Page directive it works, but if I use codebehind="...", I get a runtime error that it cannot find my first class I'm inheriting. It's almost like the...
3
2871
by: Yair Cohen | last post by:
hello 1 i use an xml documet with xml schema but when i try to use XPath (selectnodes) it retrieves empty list. when i remove the schema (the 'xmlns="http..."') i get the data. how can i handle this ? using xmlDocument.documentElement.selectNodes("PROP") something like this:
12
5816
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an asterisk is in a blob, an asterisk that is contiguous to it is in the same blob. If a blob has more than two asterisks, then each asterisk in the blob is contiguous to at least one other asterisk in the blob. For example this 12x12 grid has 6 blobs. ...
0
8126
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
8065
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
8563
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
8524
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
6052
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
4013
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...
1
2527
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
1
1656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1379
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.