473,324 Members | 2,501 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,324 software developers and data experts.

Error in Xpath

Hi there,
I need a help on making Xpaht for following xml file

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/
relationships">
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/
officeDocument/2006/relationships/extended-properties"
Target="docProps/app.xml" />
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/
package/2006/relationships/metadata/core-properties" Target="docProps/
core.xml" />
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/
officeDocument/2006/relationships/officeDocument" Target="word/
document.xml" />
</Relationships>

I need to develop a xpath based on Type attribute so that i can fetch
value in Target attribute.
I have loaded the document in XmlDocument and how want to select the
node using SelectNodes() method.

I have used following XPath query but its not working?

XmlElement element = doc.DocumentElement;
XmlNodeList nodes = element.SelectNodes("/Relationships/
Relationship[@Type=\"http://schemas.openxmlformats.org/officeDocument/
2006/relationships/officeDocument\"]");

Please help me

thankYou
miztaken
Oct 16 '08 #1
3 1487
You have xml with namespaces, which makes life much trickier. To
illustrate, I've used a namespace-manager to give the alias "r" to that
pesky uri (below).

Marc

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlElement element = doc.DocumentElement;
XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
mgr.AddNamespace("r",element.NamespaceURI);
XmlNodeList nodes =
element.SelectNodes("/r:Relationships/r:Relationship[@Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\"]",
mgr);
foreach (XmlElement el in nodes)
{
Console.WriteLine(el.Name);
}
Oct 16 '08 #2
Hi there,
Thank you for your snippet.
It worked. :-)

Can you suggest me some good book regarding XML and C#

Take Care
miztaken
Oct 17 '08 #3
Sorry, but I haven't looked... I tacked xml "back in the day" before
moving to C#, so I've never had to look at them both at the same time.

Marc
Oct 17 '08 #4

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

Similar topics

2
by: Piet | last post by:
Hello, Via Xpath, I want to access nodes which have a namespace prefix. THe document at hand is an Xsl-FO document. I tried the following: from xml.dom import minidom from xml.xpath import...
5
by: Galen Harris | last post by:
I'm getting weird errors during transformations -- "System.Net.WebException. The remote server returned an error: (500) Internal Server Error." I'm on the 1.0 Framework. I've looked through...
44
by: MadCrazyNewbie | last post by:
Hey Group, I keep getting a error saying "No Value Given For One Or More Parameters". Unfortunatly I don`t know where this error is coming from:(. Can I run through my code line by line, so I...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
8
by: Alpha | last post by:
I created the following code in my C# program but it's giving me error message at run time of : XML.XPATH.XPATHEXCEPTION : Namespace Manager or XSLTContext needed. This query has a prefix,...
0
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
4
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
0
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
0
by: jacqueharper | last post by:
I am having a problem with an Excel ListObject in my C# .NET application. I am trying to map an XML schema to a ListObject, and continue to get the error "The XPath is not valid because either the...
3
by: moralbarometer | last post by:
Please i intend to make an XML document from a string using tranformer as shown below. It returns an error which trace is given below as well. please help. public org.w3c.dom.Node getTextXML()...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.