cvcn Posted August 9, 2006 Share Posted August 9, 2006 Hi, take following xml<Parameterscol> <Parameter> <Name>PAR1</Name> <ParameterType>TYPE_ENUM_DPM</ParameterType> <ParameterEnum>test1;test2;test3</ParameterEnum> <Dependency></Dependency> <DependencyValue></DependencyValue> </Parameter> <Parameter BaseName="Parameter" RemoveOnCreate="1"> <Name>PAR2</Name> <ParameterType>TYPE_VALUE</ParameterType> <ParameterEnum></ParameterEnum> <Dependency>PAR1</Dependency> <DependencyValue></DependencyValue> </Parameter></Parameterscol>Starting from the 2 parameter DependencyValueXpath: ../Parameter[Name=PAR1]/ParameterEnum returns: test1;test2;test3How can i use the value of @Dependency to get the same result?something like ../Parameter[Name=@Dependency]/ParameterEnum is not working!! Link to comment Share on other sites More sharing options...
boen_robot Posted August 9, 2006 Share Posted August 9, 2006 Why do I have this weird deja vu.... I think I've answered this one. And I think I've answered it before the hack&back.Hopefully, now you'll tell me if what I suggest works, instead of shutting up.The path ../Parameter[Name=@Dependency]/ParameterEnum would mean that the value of @Dependancy and Name on the same Parameter must be equal before ParameterEnum is selected. The way I see it, in your XML they don't have equal values. If I gather correctly, you're trying to pull the value of @Dependency which is not on the same level.Maybe if you store that other value in a variable.... or.... uh... show me the XSLT in which you use that. I would guide myself better that way. Or are you using some other language? Link to comment Share on other sites More sharing options...
cvcn Posted August 11, 2006 Author Share Posted August 11, 2006 Thanks for the replynew XML file with test code<?xml version="1.0"?><Parameterscol><Parameter> <Name>PAR1</Name> <ParameterType>TYPE_ENUM_DPM</ParameterType> <ParameterEnum>PAR1_1;PAR1_2;PAR1_3</ParameterEnum> <Dependency></Dependency> <DependencyValue></DependencyValue></Parameter><Parameter> <Name>PAR2</Name> <ParameterType>TYPE_ENUM_DPM</ParameterType> <ParameterEnum>PAR2_1;PAR2_2;PAR2_3</ParameterEnum> <Dependency>PAR3</Dependency> <DependencyValue></DependencyValue></Parameter><Parameter> <Name>PAR3</Name> <ParameterType>TYPE_ENUM_DPM</ParameterType> <ParameterEnum>PAR3_1;PAR3_2;PAR3_3</ParameterEnum> <Dependency></Dependency> <DependencyValue></DependencyValue></Parameter></Parameterscol>I am working with VB6 & Microsoft XML,v3.0 (Msxml3.dll)this is the codePrivate Sub Command1_Click() Dim xmlProject As DOMDocument Dim xmlNodeList As IXMLDOMNodeList Dim xmlNode As IXMLDOMNode Set xmlProject = New DOMDocument xmlProject.Load "c:\tmp\text.xml" 'get all values txtInfo = "" Set xmlNodeList = xmlProject.documentElement.selectSingleNode("//Parameterscol/Parameter[1]").selectNodes("../Parameter[Name="PAR1"]/ParameterEnum") If Not xmlNodeList Is Nothing Then For Each xmlNode In xmlNodeList Debug.Print xmlNode.baseName & ": " & xmlNode.Text Next End If Set xmlNode = Nothing Set xmlNodeList = Nothing Set xmlProject = NothingEnd Sub this returns: ParameterEnum: PAR1_1;PAR1_2;PAR1_3if I change the code to Set xmlNodeList = xmlProject.documentElement.selectSingleNode("//Parameterscol/Parameter[1]").selectNodes("../Parameter[Name="PAR3"]/ParameterEnum")It returns: ParameterEnum: PAR3_1;PAR3_2;PAR3_3Now I would like the query to use the value of Parameter[1]/Dependency == "PAR1"if I change the code to Set xmlNodeList = xmlProject.documentElement.selectSingleNode("//Parameterscol/Parameter[1]").selectNodes("../Parameter[Name=//Parameterscol/Parameter[1]/Dependency]/ParameterEnum")It returns: ParameterEnum: PAR1_1;PAR1_2;PAR1_3My problem is in the real project i do not know that I can find the Dependency value at //Parameterscol/Parameter[1]/DependencyI only know that I need the Dependency value of the current selected SingleNode Link to comment Share on other sites More sharing options...
boen_robot Posted August 11, 2006 Share Posted August 11, 2006 OMG. I'm even more confused now.Anyway, as I mentioned, you could store the result in a variable, or an even more elegant method I realized theese days is to use a string() function as part of the test. At W3School's example, this means something like: ("/bookstore/book[year=string(/bookstore/book[title='Learning XML']/year)]") That would select all books, who's year is the same as the year of the book "Learning XML".In more complicated situations, storing some value as a variable may also be needed, but scince you're not using XSLT, I can't tell you how to do such manipulation. Link to comment Share on other sites More sharing options...
cvcn Posted August 11, 2006 Author Share Posted August 11, 2006 in your example there is again a const string I can only use node valuesI have changed the code to use a text box call Text1 so I can easy test some query'sSet xmlNodeList = xmlProject.documentElement.selectSingleNode("//Parameterscol/Parameter[1]").selectNodes(Text1.text)the tested query's../Parameter[Name=//Parameterscol/Parameter[1]/Dependency]/ParameterEnum -> ok ParameterEnum: PAR3_1;PAR3_2;PAR3_3../Parameter[Name=string(./Dependency)]/ParameterEnum -> bad../Parameter[//Name=./Dependency]/ParameterEnum -> bad ParameterEnum: PAR2_1;PAR2_2;PAR2_3I realy do not understand why this is not working../Parameter[Name=./Dependency]/ParameterEnum -> bad (I would expect this one to work??? because I ask the Dependency of the context node)if ./Dependency returns PAR3and ../Parameter[Name=PAR3]/ParameterEnum works okwhy is ../Parameter[Name=./Dependency]/ParameterEnum not working Link to comment Share on other sites More sharing options...
boen_robot Posted August 16, 2006 Share Posted August 16, 2006 in your example there is again a const string I can only use node valuesI have changed the code to use a text box call Text1 so I can easy test some query'sSet xmlNodeList = xmlProject.documentElement.selectSingleNode("//Parameterscol/Parameter[1]").selectNodes(Text1.text)the tested query's../Parameter[Name=//Parameterscol/Parameter[1]/Dependency]/ParameterEnum -> ok ParameterEnum: PAR3_1;PAR3_2;PAR3_3../Parameter[Name=string(./Dependency)]/ParameterEnum -> bad../Parameter[//Name=./Dependency]/ParameterEnum -> bad ParameterEnum: PAR2_1;PAR2_2;PAR2_3I realy do not understand why this is not working../Parameter[Name=./Dependency]/ParameterEnum -> bad (I would expect this one to work??? because I ask the Dependency of the context node)if ./Dependency returns PAR3and ../Parameter[Name=PAR3]/ParameterEnum works okwhy is ../Parameter[Name=./Dependency]/ParameterEnum not workingHm... could it be because you go one level further... try:../Parameter[Name=../Dependency]/ParameterEnumor should I say../Parameter[Name=string(../Dependency)]/ParameterEnum? Link to comment Share on other sites More sharing options...
cvcn Posted August 19, 2006 Author Share Posted August 19, 2006 ../Dependency is not workingI am sure I am on the ./Dependeny level because with ./Dependency I get : Dependency: PAR3and with . I get : Parameter: PAR2 TYPE_ENUM_DPM PAR2_1;PAR2_2;PAR2_3 PAR3with .. I get : Parameterscol: PAR1 TYPE_ENUM_DPM PAR1_1;PAR1_2;PAR1_3 PAR2 TYPE_ENUM_DPM PAR2_1;PAR2_2;PAR2_3 PAR3 PAR3 TYPE_ENUM_DPM PAR3_1;PAR3_2;PAR3_3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now