Groups | Blog | Home
all groups > dotnet xml > march 2004 >

dotnet xml : SelectNodes unique


Martin Honnen
3/10/2004 1:51:10 PM


[quoted text, click to view]

that is possible with the filter
[not(. = preceding-sibling::element-name)]
e.g. with the XML being

<root>
<child>1</child>
<child>2</child>
<child>1</child>
<child>3</child>
<child>1</child>
<child>2</child>
</root>

and the script (JScript)

var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
xmlDocument.async = false;
var loaded = xmlDocument.load('test20040310Result.xml');
xmlDocument.setProperty('SelectionLanguage', 'XPath');
var elements = xmlDocument.selectNodes(
'//child[not(. = preceding-sibling::child)]');
for (var i = 0; i < elements.length; i++) {
alert(elements[i].text);
}

three elements with text 1, 2, 3 are found.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jason
3/10/2004 2:38:01 PM
Hi

Would like to find out...
to get the nodes of all unique values. for example there are 9 nodes, each
of these nodes have a value. 1 node has a value of "test1", another 3 nodes
have a value of "test2" and another 5 nodes have a value of "test3". so here
i have 9 nodes in total, but i know that 3 of them have the same value, and
the other 5 have the same value. i want just 3 nodes returned because there
are 3 distinct values. exactly the same as if i were to do a "SELECT
DISTINCT surname FROM users" in SQL

Thanks
jason

Martin Honnen
3/10/2004 4:43:59 PM


[quoted text, click to view]

What do you want to extract? It is a bit odd that element names are
numbered.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jason
3/10/2004 5:20:03 PM
HI

thanks for the feed back

what if my xml doc looks like this

<root>
<child1>
<ex1>1</ex1>
<ex2>3</ex2>
</child1>
<child2>
<ex1>2</ex1>
<ex2>9</ex2>
</child2>
<child3>
<ex1>2</ex1>
<ex2>9</ex2>
</child4>
<child5>
<ex1>5</ex1>
<ex2>3</ex2>
</child5>
<child6>
<ex1>5</ex1>
<ex2>3</ex2>
</child6>
</root>

Thanks again
Jason
[quoted text, click to view]

Jason
3/10/2004 5:29:05 PM
nvrmind found it :-)

Thanks
[quoted text, click to view]

Dimitre Novatchev [MVP XML]
3/10/2004 9:52:25 PM
Read about "grouping methods" at:

http://www.topxml.com/code/default.asp?p=3&id=v20010129150851

and at:

http://jenitennison.com/xslt/grouping/index.html


Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html


[quoted text, click to view]

Maersa
3/11/2004 12:24:22 AM
jason,

could you show me how your xpath expression looks like ?

thanks,


[quoted text, click to view]

AddThis Social Bookmark Button