1

I am trying to pull names from an XML Document using a vbscript.

XML Document structure

<Aliases>
    <Alias PartyType="DF" CaseID="000000" NameType=""> Name Name</Alias>
    <Alias PartyType="DF" CaseID="000000" NameType=""> Name Name</Alias>
    <Alias PartyType="DF" CaseID="000000" NameType=""> Name Name</Alias>
    ...
</Aliases>

the XML File might have 100 rows with the same name coming from several different CaseID's because for this part of my vbscript I am trying to pull all the different Names from all cases, but here is the issue, I don't want to return duplicates.

is there a way to do this with an xPath Expression or should I try to do this with VBScript?

UpDate

using the answer below I am now getting the following error

msxml3.dll: Expected token ')' found ':'.

Aliases/Alias[@PartyType='DF' and not(./text() = preceding-sibling-->:<--:*/text())]

I tried

Aliases/Alias[@PartyType='DF' and not(./text() = preceding::/*text())]

thinking that the application might be using MSXML.net and not MSXML3 and it still gave me the same error.

???

Community
  • 1
  • 1
Malachi
  • 3,205
  • 4
  • 29
  • 46
  • you phrase it like it would be *either* VBScript or Xpath, but I hope you are using the MSXML parser in VBScript, don't you? – Doc Brown Sep 28 '12 at 17:09
  • I am not sure, I would think so. I am writing vb script to extract the Data from the XML to insert it into a form in a program. the data is extracted from a SQL Server Data Base using a dll written in C# to insert it into the XML that the application uses to store information, then the application runs the VBScript that I am writing to extract the injected information. I am still new to the applications I just started here about 3-4 months ago. – Malachi Sep 28 '12 at 18:07
  • you are not sure? Please show us the relevant code snippet you already have to read the data. – Doc Brown Oct 01 '12 at 05:34
  • I am marking the answer from FKDev because I believe that will do what I need it to do via the Xpath Query. I haven't been able to test this in the project I am working on because of the weekend and because I have run into an issue with other parts of the project that have nothing to do with this issue. but I am almost certain that FKDev has given me the answer that I am looking for with this question. – Malachi Oct 01 '12 at 18:25
  • the application does use MSXML. – Malachi Oct 02 '12 at 15:49

1 Answers1

1

Something like This maybe

/Aliases/Alias[not(./text() = preceding-sibling::*/text())]

(I haven't tried it but it should work)

Malachi
  • 3,205
  • 4
  • 29
  • 46
FKDev
  • 2,266
  • 1
  • 20
  • 23
  • will this only work for the element directly preceding it or for all elements preceding? does that make sense? – Malachi Sep 28 '12 at 16:43
  • should probably be `following-sibling`? so that I can start at the top and work my way down, but then i would have to figure out a way to skip them if they matched a previous element – Malachi Sep 28 '12 at 16:45
  • preceding-sibling will give you all the preceding elements on the same level. – FKDev Sep 28 '12 at 16:48
  • ok! I see it now. TGIF I think I just have `Code Eye` today! when I am finished writing the code I will test it and see if it works for me. I think it will though! +1 – Malachi Sep 28 '12 at 16:51
  • should it be `/Aliases/Alias[(./text() != preceding-sibling::*/text())]` ? – Malachi Sep 28 '12 at 16:55
  • msxml3 is an old thing is it ? Shouldn't you be using msxml6 ? I've tested the xpath here : http://www.online-toolz.com/tools/xpath-editor.php. It seems to work. – FKDev Oct 02 '12 at 17:24
  • it's an application that wasn't created in house. so I can't update it or anything because it's hooked into everything else. – Malachi Oct 02 '12 at 19:37
  • it also seems to work with my Full XML Document. but just not inside the application that I am working with – Malachi Oct 02 '12 at 20:22
  • In that case, you might combine XPath with code. For example get all the aliases via XPath, then use code to iterate and remove duplicates. – FKDev Oct 03 '12 at 08:27
  • I create a .dll that pulls the information and then injects it into an xml document and then the form pulls that information using vb script. so I am going to try the xPath Query that you gave me inside the .dll to remove the duplicates instead of inside the vbscript. so this will be C# stuff (something I am more Familiar with) – Malachi Oct 03 '12 at 13:25
  • thank you for your help, I finished the application I was working on, the XPath that you gave me worked out wonderfully, I took out the `not` part so that I could grab the duplicates and remove them from what I had already. – Malachi Oct 03 '12 at 16:54