I have a very simple XML document.
<SmtpGatewayRul es xmlns="http://www.foo.com/schema.xsd">
<rules>
<rule>
</rule>
</rules>
</SmtpGatewayRule s>
When no xmlns is specified I can find rule element
with calling: SelectSingleNod e("//rule");
But when namespace is specified as in the enclosed example
no node is found. Actually no element can be found in the
entire document when explicit name of it is specified.
However, when calling
SelectNodes("//*").Count
it returns 3 (correct).
What should I do to to find the element with XPath ?
should I prefix the XPath statement with namespace name
(but how, since this is a default namespace)
Or maybe should I use XmlNamespaceMan ager class when
calling the SelectSingleNod e(XPath,namespa ceManager)... ?
I tried the second option but this did not help.
I used the following code:
XmlNamespaceMan ager nm=new XmlNamespaceMan ager
(xmlDoc.NameTab le);
nm.AddNamespace ("","http://www.foo.com/schema.xsd");
XmlNode node = doc.SelectSingl eNode("//rule",nm);
//node is still null :-(
Thanks for help
Michal Januszczyk 2 3997
Michal Januszczyk wrote: What should I do to to find the element with XPath ? should I prefix the XPath statement with namespace name
Yes, you have to.
(but how, since this is a default namespace)
Remember main rule of namespaces - prefix doesn't matter. Just use any
you like. What only matters is namespace URI.
Or maybe should I use XmlNamespaceMan ager class when calling the SelectSingleNod e(XPath,namespa ceManager)... ?
I tried the second option but this did not help. I used the following code:
XmlNamespaceMan ager nm=new XmlNamespaceMan ager (xmlDoc.NameTab le); nm.AddNamespace ("","http://www.foo.com/schema.xsd");
It's a faq. See also SelectNodes method description at MSDN.
XmlNamespaceMan ager nm=new XmlNamespaceMan ager(xmlDoc.Nam eTable);
nm.AddNamespace ("foo","http ://www.foo.com/schema.xsd");
XmlNode node = doc.SelectSingl eNode("//foo:rule",nm);
--
Oleg Tkachenko
XML Insider http://www.tkachenko.com/blog
>-----Original Message----- XmlNamespaceMa nager nm=new XmlNamespaceMan ager (xmlDoc.NameTa ble); nm.AddNamespac e("foo","http ://www.foo.com/schema.xsd"); XmlNode node = doc.SelectSingl eNode("//foo:rule",nm);
Great thanks!
Michal This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike Dickens |
last post by:
hi,
i'm sure this has come up before but havn't managed to find an answer.
if i have the following xslt
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet method="xml" version="1.0" xmlns:ns1="abc"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" media-type="text/xml" standalone="yes"
version="1.0"/>
<xsl:template match="/">
|
by: S ML |
last post by:
Hello, I use the Xerces XS* classes to parse and get the definition of
an XML schema. I don't seem to find a way to get the namespace prefixes
using this framework and I read somewhere that the reason for that is
possibly because, the same namespace URI can have multiple prefixes.
But the problem I am facing is, the xpath definition specified for key,
keyref and unique elements use the namespace prefixes and these are not
converted to the...
|
by: Stanimir Stamenkov |
last post by:
I'm trying to find out if it is permissible to include a schema
document with absent target namespace to a schema with specified
target namespace, and if it is, what are the rules to resolve the
target namespace of the components from the included schema document.
I'm confused because of the rules I read in the XML Schema spec
<http://www.w3.org/TR/xmlschema-1/#element-element>:
> If the <element> element information item has <schema>...
|
by: Daniel Lidström |
last post by:
Hi,
the class looks like this:
public __gc class LandXML {
public:
...
};
|
by: Martin |
last post by:
Hi,
I have a xml file like the one below
<?xml version="1.0" encoding="utf-8"?><e1
xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2"
e1:rest="345"/>
If I try to create a schema for it with Visual Studio, I get the error
"Failed to create a schema for this data file because:
| |
by: David Thielen |
last post by:
Hi;
I set up my xml as follows:
XmlDocument xml = new XmlDocument();
xml.Load(File.Open("data.xml", FileMode.Open, FileAccess.Read));
XmlNamespaceManager context = new XmlNamespaceManager(xml.NameTable);
context.AddNamespace("", "http://www.test.org");
context.AddNamespace("sns", "http://www.test.org/sub");
XmlNode node = xml.SelectSingleNode("/root", context);
|
by: Karine Bosch |
last post by:
Hi,
My xml document uses different namespaces:
<x:root xmlns:x="x:ns:meta/">
<element1 xmlns:adam="http://ns.alfaprint.be/">
</root>
This gives problems when using an XPath query.
I already created 2 namespace managers
|
by: Plop69 |
last post by:
need some help on following:
xml file 1
<TEST xmlns="http://test" >
<OK>mlkddflmkj</OK>
</TEST>
|
by: Mark Olbert |
last post by:
I'm trying to serialize (using XmlSerializer.Serialize) a class that I generated from an XSD schema using XSD.EXE /c.
The problem I'm running into is that the root element needs to be unqualified, and the default namespace needs to be included on it
as an attribute. The schema I'm using is this:
<xs:schema
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:html="http://www.w3.org/TR/REC-html40"...
|
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...
|
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...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: 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...
| |