473,799 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XPath problem with two xmlns

I have got file raport.rld which is an XML file generated by MS Reporting
Services.

The problem is:

in this file are tags from two different namespaces

xmlns="http://schemas.microso ft.com/sqlserver/reporting/2003/10/reportdefini
tion"
xmlns:rd="http://schemas.microso ft.com/SQLServer/reporting/reportdesigner"

when I'm trying to use XPATH to get <teble> tag it doesn't work. (the
result is empty)

I've removed All tegs like

<rd:TypeName>Sy stem.Int32</rd:TypeName>

Now all is working fine but what to do when I have tags from two different
namespaces?

I don't want to remove all tags from second namespace.

Tom.

Nov 12 '05 #1
4 8978


Gismo wrote:
I have got file raport.rld which is an XML file generated by MS Reporting
Services.

The problem is:

in this file are tags from two different namespaces

xmlns="http://schemas.microso ft.com/sqlserver/reporting/2003/10/reportdefini
tion"
xmlns:rd="http://schemas.microso ft.com/SQLServer/reporting/reportdesigner"

when I'm trying to use XPATH to get <teble> tag it doesn't work. (the
result is empty)

I've removed All tegs like

<rd:TypeName>Sy stem.Int32</rd:TypeName>

Now all is working fine but what to do when I have tags from two different
namespaces?


You need to declare a prefix for every namespace and then use the prefix
in your XPath expression. How you do that depends on the environment, if
you use XPath inside of an XSLT stylesheet you can simply declare the
prefixes with
<xsl:styleshe et

xmlns:rd="xmlns :rd="http://schemas.microso ft.com/SQLServer/reporting/reportdesigner"
and then use
rd:TypeName
in your XPath expression.

If you are using an API like selectNodes/selectSingleNod e then you need
to call
xmlDocument.set Property("Selec tionNamespaces" ,

"xmlns:rd='http ://schemas.microso ft.com/SQLServer/reporting/reportdesigner' ")

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #2

Uzytkownik "Martin Honnen" <ma*******@yaho o.de> napisal w wiadomosci
news:Oq******** *****@TK2MSFTNG P09.phx.gbl...


Gismo wrote:
I have got file raport.rld which is an XML file generated by MS Reporting Services.

The problem is:

in this file are tags from two different namespaces

xmlns="http://schemas.microso ft.com/sqlserver/reporting/2003/10/reportdefini tion"
xmlns:rd="http://schemas.microso ft.com/SQLServer/reporting/reportdesigner"
when I'm trying to use XPATH to get <teble> tag it doesn't work. (the
result is empty)

I've removed All tegs like

<rd:TypeName>Sy stem.Int32</rd:TypeName>

Now all is working fine but what to do when I have tags from two different namespaces?
You need to declare a prefix for every namespace and then use the prefix
in your XPath expression. How you do that depends on the environment, if
you use XPath inside of an XSLT stylesheet you can simply declare the
prefixes with
<xsl:styleshe et

xmlns:rd="xmlns :rd="http://schemas.microso ft.com/SQLServer/reporting/reportd
esigner" and then use
rd:TypeName
in your XPath expression.

If you are using an API like selectNodes/selectSingleNod e then you need
to call
xmlDocument.set Property("Selec tionNamespaces" ,

"xmlns:rd='http ://schemas.microso ft.com/SQLServer/reporting/reportdesigner' "
)
--

Martin Honnen
http://JavaScript.FAQTs.com/

There is no method like setProperty.
My example code is:

My example code is:
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.Load("c:/tab2.xml");

XmlElement root = doc.DocumentEle ment;

XmlNodeList nodeList;
nodeList = root.SelectNode s("//Table");
if (nodeList != null)
foreach (XmlNode s1 in nodeList)
{
try
{
Console.WriteLi ne(s1.Name);
}
catch (XmlException e) {
Console.WriteLi ne(e.Message);
}
}
}
}


Gismo.

Nov 12 '05 #3


Gismo wrote:
Uzytkownik "Martin Honnen" <ma*******@yaho o.de> napisal w wiadomosci
news:Oq******** *****@TK2MSFTNG P09.phx.gbl...

Gismo wrote:

I have got file raport.rld which is an XML file generated by MS
Reporting
Services.

The problem is:

in this file are tags from two different namespaces
xmlns="http://schemas.microso ft.com/sqlserver/reporting/2003/10/reportdefini
tion"

xmlns:rd="http://schemas.microso ft.com/SQLServer/reporting/reportdesigner"
when I'm trying to use XPATH to get <teble> tag it doesn't work. (the
result is empty)

I've removed All tegs like

<rd:TypeName >System.Int32 </rd:TypeName>

Now all is working fine but what to do when I have tags from two
different
namespaces ?
You need to declare a prefix for every namespace and then use the prefix
in your XPath expression. How you do that depends on the environment, if
you use XPath inside of an XSLT stylesheet you can simply declare the
prefixes with
<xsl:styleshe et


xmlns:rd="xmlns :rd="http://schemas.microso ft.com/SQLServer/reporting/reportd
esigner"
and then use
rd:TypeName
in your XPath expression.

If you are using an API like selectNodes/selectSingleNod e then you need
to call
xmlDocument.set Property("Selec tionNamespaces" ,


"xmlns:rd='http ://schemas.microso ft.com/SQLServer/reporting/reportdesigner' "
)

There is no method like setProperty.


Sorry, I thought you might be using MSXML but you use .NET, there indeed
is no such method.

With .NET you need an XmlNamespaceMan ager and declare the prefixes for
your XPath expressions and then pass that manager to the SelectNodes method.
For instance with the example document being

<?xml version="1.0" encoding="UTF-8"?>
<gods xmlns="http://vatican.va/2004/gods">
<god name="Kibo" />
<god name="Jaffo" />
<dv:devil xmlns:dv="http://vatican.va/2004/devils" name="Xibo" />
</gods>

the following successfully queries the document using XPath

using System;
using System.Xml;

public class Test20040402 {
public static void Main (string[] args) {
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Loa d(@"test2004040 2.xml");
XmlNamespaceMan ager namespaceManage r = new
XmlNamespaceMan ager(xmlDocumen t.NameTable);
namespaceManage r.AddNamespace( "gs", "http://vatican.va/2004/gods");
namespaceManage r.AddNamespace( "dv", "http://vatican.va/2004/devils");
XmlNodeList gods = xmlDocument.Sel ectNodes("/gs:gods/gs:god",
namespaceManage r);
Console.WriteLi ne("Found {0} elements.", gods.Count);
foreach (XmlNode node in gods) {
Console.WriteLi ne(node.Name);
}
gods = xmlDocument.Sel ectNodes("/gs:gods/dv:devil", namespaceManage r);
Console.WriteLi ne("Found {0} elements.", gods.Count);
foreach (XmlNode node in gods) {
Console.WriteLi ne(node.Name);
}
}

}
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #4

Thanx, it works fine now.
:-)

Gismo.

Uzytkownik "Martin Honnen" <ma*******@yaho o.de> napisal w wiadomosci
news:#T******** ******@TK2MSFTN GP10.phx.gbl...


Gismo wrote:
Uzytkownik "Martin Honnen" <ma*******@yaho o.de> napisal w wiadomosci
news:Oq******** *****@TK2MSFTNG P09.phx.gbl...

Gismo wrote:
I have got file raport.rld which is an XML file generated by MS
Reporting
Services.

The problem is:

in this file are tags from two different namespaces


xmlns="http://schemas.microso ft.com/sqlserver/reporting/2003/10/reportdefini
tion"


xmlns:rd="http://schemas.microso ft.com/SQLServer/reporting/reportdesigner"


when I'm trying to use XPATH to get <teble> tag it doesn't work. (the
result is empty)

I've removed All tegs like

<rd:TypeName >System.Int32 </rd:TypeName>

Now all is working fine but what to do when I have tags from two


different
namespaces ?

You need to declare a prefix for every namespace and then use the prefix
in your XPath expression. How you do that depends on the environment, if
you use XPath inside of an XSLT stylesheet you can simply declare the
prefixes with
<xsl:styleshe et


xmlns:rd="xmlns :rd="http://schemas.microso ft.com/SQLServer/reporting/reportd esigner"
and then use
rd:TypeName
in your XPath expression.

If you are using an API like selectNodes/selectSingleNod e then you need
to call
xmlDocument.set Property("Selec tionNamespaces" ,


"xmlns:rd='http ://schemas.microso ft.com/SQLServer/reporting/reportdesigner' " )

There is no method like setProperty.


Sorry, I thought you might be using MSXML but you use .NET, there indeed
is no such method.

With .NET you need an XmlNamespaceMan ager and declare the prefixes for
your XPath expressions and then pass that manager to the SelectNodes

method. For instance with the example document being

<?xml version="1.0" encoding="UTF-8"?>
<gods xmlns="http://vatican.va/2004/gods">
<god name="Kibo" />
<god name="Jaffo" />
<dv:devil xmlns:dv="http://vatican.va/2004/devils" name="Xibo" />
</gods>

the following successfully queries the document using XPath

using System;
using System.Xml;

public class Test20040402 {
public static void Main (string[] args) {
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Loa d(@"test2004040 2.xml");
XmlNamespaceMan ager namespaceManage r = new
XmlNamespaceMan ager(xmlDocumen t.NameTable);
namespaceManage r.AddNamespace( "gs", "http://vatican.va/2004/gods");
namespaceManage r.AddNamespace( "dv", "http://vatican.va/2004/devils");
XmlNodeList gods = xmlDocument.Sel ectNodes("/gs:gods/gs:god",
namespaceManage r);
Console.WriteLi ne("Found {0} elements.", gods.Count);
foreach (XmlNode node in gods) {
Console.WriteLi ne(node.Name);
}
gods = xmlDocument.Sel ectNodes("/gs:gods/dv:devil", namespaceManage r); Console.WriteLi ne("Found {0} elements.", gods.Count);
foreach (XmlNode node in gods) {
Console.WriteLi ne(node.Name);
}
}

}
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #5

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

Similar topics

1
3039
by: Hollywood | last post by:
I have the following XSD created in VS.NET 2003: <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="ReferralSchama" targetNamespace="http://test.org/Referral" elementFormDefault="unqualified" xmlns="http://test.org/Referral" xmlns:mstns="http://test.org/Referral" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:complexType name="ReferralType"> <xs:sequence>
2
2882
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file - "xmlns="http://tempuri.org/nameOfRoot.xsd" I have no idea what its pointing to & what is tempuri.org? So when this tag is in my xml tag my xpath query never works. But when I delete it work fine.
3
4980
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml version="1.0" encoding="utf-8" ?> <thing xmlns="urn:thing-schema-v1"> <foo>foo thing</foo> <bar>bar thing</bar>
2
1793
by: Monty | last post by:
Despite reading posts in Google, I don't understand XPATH. Can someone help me write an XPATH. From Google I think my problem is that the default namespace does not have a prefix. I can't change this as I have received this XML and I didn't create it. All I want to is retrieve the PROJECTNAME from the following XML. I am typing this XML and XPATH into this site http://www.activsoftware.com/xml/xpath/ The XPATH that does not work is...
6
7301
by: J.Marsch | last post by:
I must be completely losing my mind. I have some code that writes to config files. It works great with app.config files, but fails miserably with web.config files. For the life of me, I cannot figure out what is going on here. I have taken it all the way back to just selecting the configuration node (top level node), and it fails! How can this line fail (returns null)??
2
3046
by: A. W. Dunstan | last post by:
I'm trying to figure out how XPath expressions work, and how I can use them to extract data into a particular format. I can extract the data I want using an XPath expression, but not with an XSLT stylesheet. Here's the Java/XPath I'm using: import java.io.*; import javax.xml.parsers.*; import org.w3c.dom.*; import org.xml.sax.SAXException;
1
3115
by: reyesvsn | last post by:
Hello everybody, I have a question concerning XPath expressions and namespaces. Consider this XML: <?xml version="1.0" encoding="UTF-8"?> <newsMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rtr="http://www.reuters.com/ns/2003/08/content" xmlns="http://iptc.org/std/nar/2006-10-01/"> <header>
0
9688
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
9546
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,...
1
10247
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
9079
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...
0
6809
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();...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.