2012-01-26 3 views
0

"XPath가 실패했습니다. 하나 이상의 항목 시퀀스가 ​​contains()의 첫 번째 인수로 허용되지 않습니다 ('string1' , 'string2') "포함 문자열을 찾기 위해 contains를 사용하려고 할 때.XPath로 문자열 시퀀스 내에서 문자열을 찾으려고 시도했습니다.

내 코드는 VariableDeclaratorId/@ 이미지 구문 분석하는 여러 필드가 두 개의 문자열을 반환하기 때문에 나는이 문제에 실행 https://stackoverflow.com/questions/9006479/with-pmd-and-xpath-can-i-determine-if-two-node-sets-have-any-node-in-common

Expression/PrimaryExpression/PrimaryPrefix 
[ 
contains(ancestor::ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration/VariableDeclarator/VariableDeclaratorId/@Image,./Name/@Image) 
] 

내 다른 질문을 해결 관련이있다. 해결책을 찾지 못했습니다. 나는이 술어를 사용하는 것에 대해 생각해 보았지만, 이미 포함되어있는 VariantDeclaratorId/@ Image [./ Name/@ Image]는이 [./Name/@Image]가 PrimaryPrefix/Name/@영상.

예상 출력 :

<Expression BeginColumn="26" BeginLine="6" EndColumn="30" EndLine="6" Image="" Label=""> 
     <PrimaryExpression BeginColumn="26" BeginLine="6" EndColumn="30" EndLine="6" Image="" Label=""> 
      <PrimaryPrefix BeginColumn="26" BeginLine="6" EndColumn="30" EndLine="6" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
       <Name BeginColumn="26" BeginLine="6" EndColumn="30" EndLine="6" Image="m_foo" Label=""/> 
      </PrimaryPrefix> 
     </PrimaryExpression> 
    </Expression> 


    <Expression BeginColumn="26" BeginLine="7" EndColumn="30" EndLine="7" Image="" Label=""> 
     <PrimaryExpression BeginColumn="26" BeginLine="7" EndColumn="30" EndLine="7" Image="" Label=""> 
      <PrimaryPrefix BeginColumn="26" BeginLine="7" EndColumn="30" EndLine="7" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
       <Name BeginColumn="26" BeginLine="7" EndColumn="30" EndLine="7" Image="m_two" Label=""/> 
      </PrimaryPrefix> 
     </PrimaryExpression> 
    </Expression> 

Jave 출처 :

public class domainFunction { 
    private int m_foo; // OK 

    public void bar() { 
     calculate (random); 
     System.out.println(m_foo); 
     System.out.println(m_two); 
    } 
    } 

RAW XML :

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    <CompilationUnit BeginColumn="1" BeginLine="1" EndColumn="3" EndLine="13" Image="" Label="" declarationsAreInDefaultPackage="true"> 
     <TypeDeclaration BeginColumn="1" BeginLine="1" EndColumn="3" EndLine="13" Image="" Label=""> 
      <ClassOrInterfaceDeclaration Abstract="false" BeginColumn="8" BeginLine="1" EndColumn="3" EndLine="13" Final="false" Image="domainFunction" Interface="false" Label="" Modifiers="1" Native="false" Nested="false" PackagePrivate="false" Private="false" Protected="false" Public="true" Static="false" Strictfp="false" Synchronized="false" Transient="false" Volatile="false"> 
       <ClassOrInterfaceBody BeginColumn="29" BeginLine="1" EndColumn="3" EndLine="13" Image="" Label=""> 
        <ClassOrInterfaceBodyDeclaration AnonymousInnerClass="false" BeginColumn="5" BeginLine="2" EndColumn="22" EndLine="2" EnumChild="false" Image="" Label=""> 
         <FieldDeclaration Abstract="false" Array="false" ArrayDepth="0" BeginColumn="13" BeginLine="2" EndColumn="22" EndLine="2" Final="false" Image="" InterfaceMember="false" Label="" Modifiers="4" Native="false" PackagePrivate="false" Private="true" Protected="false" Public="false" Static="false" Strictfp="false" Synchronized="false" SyntacticallyFinal="false" SyntacticallyPublic="false" SyntacticallyStatic="false" Transient="false" VariableName="m_foo" Volatile="false"> 
          <Type Array="false" ArrayDepth="0" BeginColumn="13" BeginLine="2" EndColumn="15" EndLine="2" Image="" Label="" TypeImage="int"> 
           <PrimitiveType Array="false" ArrayDepth="0" BeginColumn="13" BeginLine="2" Boolean="false" EndColumn="15" EndLine="2" Image="int" Label=""/> 
          </Type> 
          <VariableDeclarator BeginColumn="17" BeginLine="2" EndColumn="21" EndLine="2" Image="" Label=""> 
           <VariableDeclaratorId Array="false" ArrayDepth="0" BeginColumn="17" BeginLine="2" EndColumn="21" EndLine="2" ExceptionBlockParameter="false" Image="m_foo" Label=""/> 
          </VariableDeclarator> 
         </FieldDeclaration> 
        </ClassOrInterfaceBodyDeclaration> 
        <ClassOrInterfaceBodyDeclaration AnonymousInnerClass="false" BeginColumn="5" BeginLine="3" EndColumn="22" EndLine="3" EnumChild="false" Image="" Label=""> 
         <FieldDeclaration Abstract="false" Array="false" ArrayDepth="0" BeginColumn="13" BeginLine="3" EndColumn="22" EndLine="3" Final="false" Image="" InterfaceMember="false" Label="" Modifiers="4" Native="false" PackagePrivate="false" Private="true" Protected="false" Public="false" Static="false" Strictfp="false" Synchronized="false" SyntacticallyFinal="false" SyntacticallyPublic="false" SyntacticallyStatic="false" Transient="false" VariableName="m_two" Volatile="false"> 
          <Type Array="false" ArrayDepth="0" BeginColumn="13" BeginLine="3" EndColumn="15" EndLine="3" Image="" Label="" TypeImage="int"> 
           <PrimitiveType Array="false" ArrayDepth="0" BeginColumn="13" BeginLine="3" Boolean="false" EndColumn="15" EndLine="3" Image="int" Label=""/> 
          </Type> 
          <VariableDeclarator BeginColumn="17" BeginLine="3" EndColumn="21" EndLine="3" Image="" Label=""> 
           <VariableDeclaratorId Array="false" ArrayDepth="0" BeginColumn="17" BeginLine="3" EndColumn="21" EndLine="3" ExceptionBlockParameter="false" Image="m_two" Label=""/> 
          </VariableDeclarator> 
         </FieldDeclaration> 
        </ClassOrInterfaceBodyDeclaration> 
        <ClassOrInterfaceBodyDeclaration AnonymousInnerClass="false" BeginColumn="5" BeginLine="4" EndColumn="5" EndLine="11" EnumChild="false" Image="" Label=""> 
         <MethodDeclaration Abstract="false" BeginColumn="12" BeginLine="4" EndColumn="5" EndLine="11" Final="false" Image="" InterfaceMember="false" Label="" MethodName="bar" Modifiers="1" Native="false" PackagePrivate="false" Private="false" Protected="false" Public="true" Static="false" Strictfp="false" Synchronized="false" SyntacticallyAbstract="false" SyntacticallyPublic="true" Transient="false" Void="true" Volatile="false"> 
          <ResultType BeginColumn="12" BeginLine="4" EndColumn="15" EndLine="4" Image="" Label="" Void="true" returnsArray="false"/> 
          <MethodDeclarator BeginColumn="17" BeginLine="4" EndColumn="21" EndLine="4" Image="bar" Label="" ParameterCount="0"> 
           <FormalParameters BeginColumn="20" BeginLine="4" EndColumn="21" EndLine="4" Image="" Label="" ParameterCount="0"/> 
          </MethodDeclarator> 
          <Block BeginColumn="23" BeginLine="4" EndColumn="5" EndLine="11" Image="" Label="" containsComment="false"> 
           <BlockStatement Allocation="false" BeginColumn="7" BeginLine="5" EndColumn="22" EndLine="5" Image="" Label=""> 
            <LocalVariableDeclaration Abstract="false" Array="false" ArrayDepth="0" BeginColumn="7" BeginLine="5" EndColumn="21" EndLine="5" Final="false" Image="" Label="" Modifiers="0" Native="false" PackagePrivate="true" Private="false" Protected="false" Public="false" Static="false" Strictfp="false" Synchronized="false" Transient="false" VariableName="random" Volatile="false"> 
             <Type Array="false" ArrayDepth="0" BeginColumn="7" BeginLine="5" EndColumn="9" EndLine="5" Image="" Label="" TypeImage="int"> 
              <PrimitiveType Array="false" ArrayDepth="0" BeginColumn="7" BeginLine="5" Boolean="false" EndColumn="9" EndLine="5" Image="int" Label=""/> 
             </Type> 
             <VariableDeclarator BeginColumn="11" BeginLine="5" EndColumn="21" EndLine="5" Image="" Label=""> 
              <VariableDeclaratorId Array="false" ArrayDepth="0" BeginColumn="11" BeginLine="5" EndColumn="16" EndLine="5" ExceptionBlockParameter="false" Image="random" Label=""/> 
              <VariableInitializer BeginColumn="20" BeginLine="5" EndColumn="21" EndLine="5" Image="" Label=""> 
               <Expression BeginColumn="20" BeginLine="5" EndColumn="21" EndLine="5" Image="" Label=""> 
                <PrimaryExpression BeginColumn="20" BeginLine="5" EndColumn="21" EndLine="5" Image="" Label=""> 
                 <PrimaryPrefix BeginColumn="20" BeginLine="5" EndColumn="21" EndLine="5" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
                  <Literal BeginColumn="20" BeginLine="5" CharLiteral="false" EndColumn="21" EndLine="5" FloatLiteral="false" Image="12" IntLiteral="true" Label="" SingleCharacterStringLiteral="false" StringLiteral="false"/> 
                 </PrimaryPrefix> 
                </PrimaryExpression> 
               </Expression> 
              </VariableInitializer> 
             </VariableDeclarator> 
            </LocalVariableDeclaration> 
           </BlockStatement> 
           <BlockStatement Allocation="false" BeginColumn="7" BeginLine="6" EndColumn="25" EndLine="6" Image="" Label=""> 
            <Statement BeginColumn="7" BeginLine="6" EndColumn="25" EndLine="6" Image="" Label=""> 
             <StatementExpression BeginColumn="7" BeginLine="6" EndColumn="24" EndLine="6" Image="" Label=""> 
              <PrimaryExpression BeginColumn="7" BeginLine="6" EndColumn="24" EndLine="6" Image="" Label=""> 
               <PrimaryPrefix BeginColumn="7" BeginLine="6" EndColumn="15" EndLine="6" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
                <Name BeginColumn="7" BeginLine="6" EndColumn="15" EndLine="6" Image="calculate" Label=""/> 
               </PrimaryPrefix> 
               <PrimarySuffix ArgumentCount="1" Arguments="true" ArrayDereference="false" BeginColumn="17" BeginLine="6" EndColumn="24" EndLine="6" Image="" Label=""> 
                <Arguments ArgumentCount="1" BeginColumn="17" BeginLine="6" EndColumn="24" EndLine="6" Image="" Label=""> 
                 <ArgumentList BeginColumn="18" BeginLine="6" EndColumn="23" EndLine="6" Image="" Label=""> 
                  <Expression BeginColumn="18" BeginLine="6" EndColumn="23" EndLine="6" Image="" Label=""> 
                   <PrimaryExpression BeginColumn="18" BeginLine="6" EndColumn="23" EndLine="6" Image="" Label=""> 
                    <PrimaryPrefix BeginColumn="18" BeginLine="6" EndColumn="23" EndLine="6" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
                     <Name BeginColumn="18" BeginLine="6" EndColumn="23" EndLine="6" Image="random" Label=""/> 
                    </PrimaryPrefix> 
                   </PrimaryExpression> 
                  </Expression> 
                 </ArgumentList> 
                </Arguments> 
               </PrimarySuffix> 
              </PrimaryExpression> 
             </StatementExpression> 
            </Statement> 
           </BlockStatement> 
           <BlockStatement Allocation="false" BeginColumn="7" BeginLine="7" EndColumn="24" EndLine="7" Image="" Label=""> 
            <Statement BeginColumn="7" BeginLine="7" EndColumn="24" EndLine="7" Image="" Label=""> 
             <StatementExpression BeginColumn="7" BeginLine="7" EndColumn="23" EndLine="7" Image="" Label=""> 
              <PrimaryExpression BeginColumn="7" BeginLine="7" EndColumn="23" EndLine="7" Image="" Label=""> 
               <PrimaryPrefix BeginColumn="7" BeginLine="7" EndColumn="15" EndLine="7" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
                <Name BeginColumn="7" BeginLine="7" EndColumn="15" EndLine="7" Image="calculate" Label=""/> 
               </PrimaryPrefix> 
               <PrimarySuffix ArgumentCount="1" Arguments="true" ArrayDereference="false" BeginColumn="17" BeginLine="7" EndColumn="23" EndLine="7" Image="" Label=""> 
                <Arguments ArgumentCount="1" BeginColumn="17" BeginLine="7" EndColumn="23" EndLine="7" Image="" Label=""> 
                 <ArgumentList BeginColumn="18" BeginLine="7" EndColumn="22" EndLine="7" Image="" Label=""> 
                  <Expression BeginColumn="18" BeginLine="7" EndColumn="22" EndLine="7" Image="" Label=""> 
                   <PrimaryExpression BeginColumn="18" BeginLine="7" EndColumn="22" EndLine="7" Image="" Label=""> 
                    <PrimaryPrefix BeginColumn="18" BeginLine="7" EndColumn="22" EndLine="7" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
                     <Name BeginColumn="18" BeginLine="7" EndColumn="22" EndLine="7" Image="m_foo" Label=""/> 
                    </PrimaryPrefix> 
                   </PrimaryExpression> 
                  </Expression> 
                 </ArgumentList> 
                </Arguments> 
               </PrimarySuffix> 
              </PrimaryExpression> 
             </StatementExpression> 
            </Statement> 
           </BlockStatement> 
           <BlockStatement Allocation="false" BeginColumn="7" BeginLine="8" EndColumn="32" EndLine="8" Image="" Label=""> 
            <Statement BeginColumn="7" BeginLine="8" EndColumn="32" EndLine="8" Image="" Label=""> 
             <StatementExpression BeginColumn="7" BeginLine="8" EndColumn="31" EndLine="8" Image="" Label=""> 
              <PrimaryExpression BeginColumn="7" BeginLine="8" EndColumn="31" EndLine="8" Image="" Label=""> 
               <PrimaryPrefix BeginColumn="7" BeginLine="8" EndColumn="24" EndLine="8" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
                <Name BeginColumn="7" BeginLine="8" EndColumn="24" EndLine="8" Image="System.out.println" Label=""/> 
               </PrimaryPrefix> 
               <PrimarySuffix ArgumentCount="1" Arguments="true" ArrayDereference="false" BeginColumn="25" BeginLine="8" EndColumn="31" EndLine="8" Image="" Label=""> 
                <Arguments ArgumentCount="1" BeginColumn="25" BeginLine="8" EndColumn="31" EndLine="8" Image="" Label=""> 
                 <ArgumentList BeginColumn="26" BeginLine="8" EndColumn="30" EndLine="8" Image="" Label=""> 
                  <Expression BeginColumn="26" BeginLine="8" EndColumn="30" EndLine="8" Image="" Label=""> 
                   <PrimaryExpression BeginColumn="26" BeginLine="8" EndColumn="30" EndLine="8" Image="" Label=""> 
                    <PrimaryPrefix BeginColumn="26" BeginLine="8" EndColumn="30" EndLine="8" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
                     <Name BeginColumn="26" BeginLine="8" EndColumn="30" EndLine="8" Image="m_foo" Label=""/> 
                    </PrimaryPrefix> 
                   </PrimaryExpression> 
                  </Expression> 
                 </ArgumentList> 
                </Arguments> 
               </PrimarySuffix> 
              </PrimaryExpression> 
             </StatementExpression> 
            </Statement> 
           </BlockStatement> 
           <BlockStatement Allocation="false" BeginColumn="7" BeginLine="9" EndColumn="32" EndLine="9" Image="" Label=""> 
            <Statement BeginColumn="7" BeginLine="9" EndColumn="32" EndLine="9" Image="" Label=""> 
             <StatementExpression BeginColumn="7" BeginLine="9" EndColumn="31" EndLine="9" Image="" Label=""> 
              <PrimaryExpression BeginColumn="7" BeginLine="9" EndColumn="31" EndLine="9" Image="" Label=""> 
               <PrimaryPrefix BeginColumn="7" BeginLine="9" EndColumn="24" EndLine="9" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
                <Name BeginColumn="7" BeginLine="9" EndColumn="24" EndLine="9" Image="System.out.println" Label=""/> 
               </PrimaryPrefix> 
               <PrimarySuffix ArgumentCount="1" Arguments="true" ArrayDereference="false" BeginColumn="25" BeginLine="9" EndColumn="31" EndLine="9" Image="" Label=""> 
                <Arguments ArgumentCount="1" BeginColumn="25" BeginLine="9" EndColumn="31" EndLine="9" Image="" Label=""> 
                 <ArgumentList BeginColumn="26" BeginLine="9" EndColumn="30" EndLine="9" Image="" Label=""> 
                  <Expression BeginColumn="26" BeginLine="9" EndColumn="30" EndLine="9" Image="" Label=""> 
                   <PrimaryExpression BeginColumn="26" BeginLine="9" EndColumn="30" EndLine="9" Image="" Label=""> 
                    <PrimaryPrefix BeginColumn="26" BeginLine="9" EndColumn="30" EndLine="9" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
                     <Name BeginColumn="26" BeginLine="9" EndColumn="30" EndLine="9" Image="m_two" Label=""/> 
                    </PrimaryPrefix> 
                   </PrimaryExpression> 
                  </Expression> 
                 </ArgumentList> 
                </Arguments> 
               </PrimarySuffix> 
              </PrimaryExpression> 
             </StatementExpression> 
            </Statement> 
           </BlockStatement> 
           <BlockStatement Allocation="false" BeginColumn="7" BeginLine="10" EndColumn="28" EndLine="10" Image="" Label=""> 
            <Statement BeginColumn="7" BeginLine="10" EndColumn="28" EndLine="10" Image="" Label=""> 
             <StatementExpression BeginColumn="7" BeginLine="10" EndColumn="27" EndLine="10" Image="" Label=""> 
              <PrimaryExpression BeginColumn="7" BeginLine="10" EndColumn="27" EndLine="10" Image="" Label=""> 
               <PrimaryPrefix BeginColumn="7" BeginLine="10" EndColumn="10" EndLine="10" Image="" Label="this" SuperModifier="false" ThisModifier="true"/> 
               <PrimarySuffix ArgumentCount="" Arguments="false" ArrayDereference="false" BeginColumn="11" BeginLine="10" EndColumn="20" EndLine="10" Image="calculate" Label=""/> 
               <PrimarySuffix ArgumentCount="1" Arguments="true" ArrayDereference="false" BeginColumn="21" BeginLine="10" EndColumn="27" EndLine="10" Image="" Label=""> 
                <Arguments ArgumentCount="1" BeginColumn="21" BeginLine="10" EndColumn="27" EndLine="10" Image="" Label=""> 
                 <ArgumentList BeginColumn="22" BeginLine="10" EndColumn="26" EndLine="10" Image="" Label=""> 
                  <Expression BeginColumn="22" BeginLine="10" EndColumn="26" EndLine="10" Image="" Label=""> 
                   <PrimaryExpression BeginColumn="22" BeginLine="10" EndColumn="26" EndLine="10" Image="" Label=""> 
                    <PrimaryPrefix BeginColumn="22" BeginLine="10" EndColumn="26" EndLine="10" Image="" Label="" SuperModifier="false" ThisModifier="false"> 
                     <Name BeginColumn="22" BeginLine="10" EndColumn="26" EndLine="10" Image="m_foo" Label=""/> 
                    </PrimaryPrefix> 
                   </PrimaryExpression> 
                  </Expression> 
                 </ArgumentList> 
                </Arguments> 
               </PrimarySuffix> 
              </PrimaryExpression> 
             </StatementExpression> 
            </Statement> 
           </BlockStatement> 
          </Block> 
         </MethodDeclaration> 
        </ClassOrInterfaceBodyDeclaration> 
       </ClassOrInterfaceBody> 
      </ClassOrInterfaceDeclaration> 
     </TypeDeclaration> 
    </CompilationUnit> 
+0

안녕하세요, @ttback. 대답을 얻지 못하는 이유는 (이 질문 또는 이전 질문에) 쉬운 대답을 제공하는 질문을 작성하지 않았기 때문입니다. 입력 한 XML (사용자가 수행 한)과 해당 입력을 기반으로 찾고자하는 정확한 * 원하는 출력을 항상 제공해야합니다. 여기서 우리는 당신이받은 오류와 당신이 시도한 임의의 표현을 보여 주었지만, 예상되는 결과가 무엇인지를 결코 알려주지 않았습니다. * 우리는 마음을 읽을 수 없습니다 *. –

+0

@ lwburk : 더 명확하게 할 수 있다면 예상 출력을 추가했습니다. 죄송합니다. 충분히 명확하지 않으면 게시 할 때 조금 돌진했습니다. 내 마음에는 엄청난 것들이 있었다. – ttback

답변

0

난 당신이 사용하는 생각 contains() 함수는 문자열 집합에 주어진 문자열이 포함되어 있는지 여부를 잘못 판단한 것이므로 사용하지 마십시오. 추측하지 말고, spec을 읽어라. 그것은 contains()가하는 것과 다르다. 오히려 한 문자열에 다른 문자열이 부분 문자열로 들어 있는지 테스트합니다. 문자열 $ S에 문자열 $ T가 포함되어 있는지 테스트하려면 ($ S = $ T)를 사용하십시오.

+0

감사합니다. 해결 됐어. 오늘까지이 스펙을 찾지 못했습니다. XPath를 충분히 살펴 보지 않고 PMD의 문서를 읽고 추측하는 데 너무 많은 시간을 낭비했습니다. 또한 어느 시점에서 XPath 스펙 PMD가 사용 중인지 확실하지 않았습니다. 이러한 기본 사항을 정렬하는 데는 시간이 걸렸습니다. 다시 한번 감사드립니다. – ttback

관련 문제