I've an xml document that looks a bit like this
<Vendors>
<Vendor Stationery="Fre d" />
<Vendor Stationery="ber t" />
<Vendor Stationery="ber t" />
</Vendors>
I want to extract a list of the distinct values of Stationery. I've found
some things on the web that suggest XPath statements to do this (in XSLT),
but I get the error 'The Expression passed to this should result in a node
set with my attempts. Here is my code
String XPathString = "Vendor/[not(@InvoiceSta tionery =
preceding-sibling::Vendor/@InvoiceStation ery]@InvoiceStation ery";
XmlNodeList Stationery = xmlVendors.Sele ctNodes(XPathSt ring);
I can select fine with Vendor/@InvoiceStation ery, but with the duplications.
I've tried several variations but I am unsure if it is the XPath or
something else. My GUESS is that the error means that the return is a
scalar value and not nodes, but I don't find it the clearest description
ever!
Iain 4 5290
Iain wrote: <Vendors> <Vendor Stationery="Fre d" /> <Vendor Stationery="ber t" /> <Vendor Stationery="ber t" /> </Vendors>
I want to extract a list of the distinct values of Stationery. I've found some things on the web that suggest XPath statements to do this (in XSLT), but I get the error 'The Expression passed to this should result in a node set with my attempts. Here is my code
String XPathString = "Vendor/[not(@InvoiceSta tionery = preceding-sibling::Vendor/@InvoiceStation ery]@InvoiceStation ery";
Well,
1) in your XML there is no InvoiceStatione ry attribute.
2) several syntax errors, try
String XPathString = "Vendor/[not(@Stationery =
preceding-sibling::Vendor/@Stationery)]/@Stationery";
Beware, that's goind to be deadly slow on big XML documents.
Much scalable solution is to leverage EXSLT.NET [1] set:distinct
extension function.
[1] http://workspaces.gotdotnet.com/exslt
--
Oleg Tkachenko [XML MVP, XmlInsider] http://blog.tkachenko.com
Thanks, Oleg. In real life I had the attribute InvoiceStatione ry, but
shortened it for the example. For simplicity I've now set the attribute
name to be Stationery and provided a 3 line sample ...
But. Your code copied as is does not work. It does the same thing.
I'm doing this with an XmlDocument - that should be OK, should it not?
XmlDocument xx = new XmlDocument();
xx.LoadXml("<Ve ndors><Vendor Stationery=\"Fr ed\" /> <Vendor
Stationery=\"be rt\" /> <Vendor Stationery=\"be rt\" /></Vendors>");
String XPathString = "Vendor/[not(@Stationery =
preceding-sibling::Vendor/@Stationery)]/@Stationery";
XmlNodeList test = xx.SelectNodes( XPathString);
Thanks
iain
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:#X******** ******@TK2MSFTN GP09.phx.gbl... Well, 1) in your XML there is no InvoiceStatione ry attribute. 2) several syntax errors, try String XPathString = "Vendor/[not(@Stationery = preceding-sibling::Vendor/@Stationery)]/@Stationery";
Beware, that's goind to be deadly slow on big XML documents. Much scalable solution is to leverage EXSLT.NET [1] set:distinct extension function. [1] http://workspaces.gotdotnet.com/exslt -- Oleg Tkachenko [XML MVP, XmlInsider] http://blog.tkachenko.com
Iain wrote: Thanks, Oleg. In real life I had the attribute InvoiceStatione ry, but shortened it for the example. For simplicity I've now set the attribute name to be Stationery and provided a 3 line sample ...
But. Your code copied as is does not work. It does the same thing.
I'm doing this with an XmlDocument - that should be OK, should it not?
XmlDocument xx = new XmlDocument(); xx.LoadXml("<Ve ndors><Vendor Stationery=\"Fr ed\" /> <Vendor Stationery=\"be rt\" /> <Vendor Stationery=\"be rt\" /></Vendors>");
String XPathString = "Vendor/[not(@Stationery = preceding-sibling::Vendor/@Stationery)]/@Stationery";
Syntax error again. It should be
Vendor[not(@Stationery =
preceding-sibling::Vendor/@Stationery)]/@Stationery"
And as this expression starts with Vendor, it must be executed on
Vendors element:
xx.DocumentElem ent.SelectNodes (XPathString);
Then it gives me 2 distinct Stationery attributes.
--
Oleg Tkachenko [XML MVP, XmlInsider] http://blog.tkachenko.com
Thanks very much. I'm still struggling with XPath - not really getting my
mind round it.
In the meantime, I just selected all the nodes, copied the values to an
array, sorted it and skipped the duplicates (incidentally, I was amazed at
how easy this was to do. Try doing this in C++ in roughly 30 seconds!). I
feel ashamed, but it works and may even be more efficient!
But I'm glad to know how I should have done it!
Iain
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:ui******** ******@TK2MSFTN GP12.phx.gbl... Iain wrote:
Thanks, Oleg. In real life I had the attribute InvoiceStatione ry, but shortened it for the example. For simplicity I've now set the attribute name to be Stationery and provided a 3 line sample ...
But. Your code copied as is does not work. It does the same thing.
I'm doing this with an XmlDocument - that should be OK, should it not?
XmlDocument xx = new XmlDocument(); xx.LoadXml("<Ve ndors><Vendor Stationery=\"Fr ed\" /> <Vendor Stationery=\"be rt\" /> <Vendor Stationery=\"be rt\" /></Vendors>");
String XPathString = "Vendor/[not(@Stationery = preceding-sibling::Vendor/@Stationery)]/@Stationery";
Syntax error again. It should be Vendor[not(@Stationery = preceding-sibling::Vendor/@Stationery)]/@Stationery"
And as this expression starts with Vendor, it must be executed on Vendors element: xx.DocumentElem ent.SelectNodes (XPathString);
Then it gives me 2 distinct Stationery attributes. -- Oleg Tkachenko [XML MVP, XmlInsider] http://blog.tkachenko.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kelvin |
last post by:
Okay so this is baking my noodle. I want to select all the
attritbutes/fields from a table but then to excluded any row in which
a single attributes data has been duplicated.
I.E. Here's my table:-
ID Ref Name DATE
1 AAA Joe 1/2
2 BBB Ken 1/2
3 AAA Len 6/3
|
by: Chris Belcher |
last post by:
First some background...
The database tracks Action Items assigned to a group of 20 or so
managers. Once the assignment is created it is then emailed to each of
the managers that are included in the scope of the assignment. Among the
functions that it provides is the ability to embed the source documents
in the database using OLE. The user has requested the ability to forward
the source document with the email. The embedded documents...
|
by: news |
last post by:
I am trying to get at the source of a web page. Looking at the innerHTML element is only part of the story. In IE, right-clicking on various different parts of the page gives me different results when I click on view_source.
The source I need is contained inside IFRAME tags (which contain references to jsp pages)... The html content isn't available when I look at the innerHTML of the document returned in the DocumentComplete event of the...
|
by: Thomas R. Hummel |
last post by:
Hello,
I am currently working on a monthly load process with a datamart. I
originally designed the tables in a normalized fashion with the idea
that I would denormalize as needed once I got an idea of what the
performance was like. There were some performance problems, so the
decision was made to denormalize. Now the users are happy with the
query performance, but loading the tables is much more difficult.
Specifically...
|
by: Kevin K |
last post by:
Hi,
I'm having a problem with extracting text from a Word document using
StreamReader. As I'm developing a web application, I do NOT want the server
to make calls to Word. I want to simply open the Word document via
StreamReader and extract the text.
Here's the problem, the users insist on leaving the "Track Changes" features
on. Because of this, the raw text portion of the file contains the change
history. I don't want the...
| |
by: aglaforge |
last post by:
I'm attempting to write a quick piece of Javascript code that will
validate if the end user of the javascript has the necessary VML
attributes set in their HTML. The problem in IE is that "xmlns:v"
does not appear in their attributes property or the
getAttribute('xmlns:v') calls. The real kicker is that the 'xmlns'
attribute does return something.
The HTML Snippet would look like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
|
by: Damien |
last post by:
I have seen examples of selecting distinct elements by name, but my
issue is that I need to get distinct attributes by name. My XML looks
like:
<root>
<file>
<rows>
<row att1="1" />
<row att2="2" />
<row att1="1" att2="2" />
|
by: Debbiedo |
last post by:
My software program outputs an XML Driving Directions file that I need
to input into an Access table (although if need be I can import a dbf
or xls) so that I can relate one of the fields (fromStop) and its
associated driving directions back to a relational database. I have
asked my software vendor for solutions but thus far they have not come
up with anything. I am totally unfamiliar with XML so I am struggling
with how to do this. I have...
|
by: rds80 |
last post by:
In the xml document below, I would like to retrieve the distinct
attributes for the element '<Bal>'. However, I haven't had any
success. Here is what I have so far:
<TRANS>
<TRAN TRAN_DESC_CD="ACRT" TRAN_DESC="Actual Rate">
|
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...
|
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...
| |
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,...
|
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: 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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |