C++ 无法使用libxml2处理xpath查询

C++ 无法使用libxml2处理xpath查询,c++,xml-parsing,libxml2,C++,Xml Parsing,Libxml2,我在下面提到了xml路径查询 <saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="_a75adf55-01d7-40cc-929f-

我在下面提到了xml路径查询

                                <saml:Assertion MajorVersion="1"
                                                        MinorVersion="1"
                                                        AssertionID="_a75adf55-01d7-40cc-929f-dbd8372ebdfc"
                                                        Issuer="SAML_AUTH_URI"
                                                        IssueInstant="2005-06-08T12:00:01.100Z">
                                        <saml:AuthenticationStatement
                                                        AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
                                                        AuthenticationInstant="2005-06-08T11:59:59.000Z">
                                                <saml:Subject>
                                                        <saml:NameIdentifier>jre</saml:NameIdentifier>
                                                </saml:Subject>
                                        </saml:AuthenticationStatement>
                                        <saml:AttributeStatement>
                                                <saml:Attribute
                                                                AttributeName="role"
                                                                AttributeNamespace="oasis:names:tc:xacml:2.0:subject">
                                                        <saml:AttributeValue>weboamadmin</saml:AttributeValue>
                                                </saml:Attribute>
                                        </saml:AttributeStatement>
                                </saml:Assertion>

                        </samlp:Response>
                </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>
//名称空间 char*pszNs\u Soap\u prefix=“s”; char*pszNs_Soap_URL=“”

                                <saml:Assertion MajorVersion="1"
                                                        MinorVersion="1"
                                                        AssertionID="_a75adf55-01d7-40cc-929f-dbd8372ebdfc"
                                                        Issuer="SAML_AUTH_URI"
                                                        IssueInstant="2005-06-08T12:00:01.100Z">
                                        <saml:AuthenticationStatement
                                                        AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
                                                        AuthenticationInstant="2005-06-08T11:59:59.000Z">
                                                <saml:Subject>
                                                        <saml:NameIdentifier>jre</saml:NameIdentifier>
                                                </saml:Subject>
                                        </saml:AuthenticationStatement>
                                        <saml:AttributeStatement>
                                                <saml:Attribute
                                                                AttributeName="role"
                                                                AttributeNamespace="oasis:names:tc:xacml:2.0:subject">
                                                        <saml:AttributeValue>weboamadmin</saml:AttributeValue>
                                                </saml:Attribute>
                                        </saml:AttributeStatement>
                                </saml:Assertion>

                        </samlp:Response>
                </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>
char*pszNs_SamlP_Prefix=“sp”; char*pszNS_SamlP_URL=“urn:oasis:names:tc:SAML:1.0:protocol”

                                <saml:Assertion MajorVersion="1"
                                                        MinorVersion="1"
                                                        AssertionID="_a75adf55-01d7-40cc-929f-dbd8372ebdfc"
                                                        Issuer="SAML_AUTH_URI"
                                                        IssueInstant="2005-06-08T12:00:01.100Z">
                                        <saml:AuthenticationStatement
                                                        AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
                                                        AuthenticationInstant="2005-06-08T11:59:59.000Z">
                                                <saml:Subject>
                                                        <saml:NameIdentifier>jre</saml:NameIdentifier>
                                                </saml:Subject>
                                        </saml:AuthenticationStatement>
                                        <saml:AttributeStatement>
                                                <saml:Attribute
                                                                AttributeName="role"
                                                                AttributeNamespace="oasis:names:tc:xacml:2.0:subject">
                                                        <saml:AttributeValue>weboamadmin</saml:AttributeValue>
                                                </saml:Attribute>
                                        </saml:AttributeStatement>
                                </saml:Assertion>

                        </samlp:Response>
                </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>
char*pszNS_Saml_Prefix=“sl”; char*pszNS_Saml_URL=“urn:oasis:names:tc:Saml:1.0:assertion”

                                <saml:Assertion MajorVersion="1"
                                                        MinorVersion="1"
                                                        AssertionID="_a75adf55-01d7-40cc-929f-dbd8372ebdfc"
                                                        Issuer="SAML_AUTH_URI"
                                                        IssueInstant="2005-06-08T12:00:01.100Z">
                                        <saml:AuthenticationStatement
                                                        AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
                                                        AuthenticationInstant="2005-06-08T11:59:59.000Z">
                                                <saml:Subject>
                                                        <saml:NameIdentifier>jre</saml:NameIdentifier>
                                                </saml:Subject>
                                        </saml:AuthenticationStatement>
                                        <saml:AttributeStatement>
                                                <saml:Attribute
                                                                AttributeName="role"
                                                                AttributeNamespace="oasis:names:tc:xacml:2.0:subject">
                                                        <saml:AttributeValue>weboamadmin</saml:AttributeValue>
                                                </saml:Attribute>
                                        </saml:AttributeStatement>
                                </saml:Assertion>

                        </samlp:Response>
                </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>
但是从xmlXPathEvalExpression库函数中获取NULL,上面是我的xpath查询,不知道哪里出错了。

                                <saml:Assertion MajorVersion="1"
                                                        MinorVersion="1"
                                                        AssertionID="_a75adf55-01d7-40cc-929f-dbd8372ebdfc"
                                                        Issuer="SAML_AUTH_URI"
                                                        IssueInstant="2005-06-08T12:00:01.100Z">
                                        <saml:AuthenticationStatement
                                                        AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
                                                        AuthenticationInstant="2005-06-08T11:59:59.000Z">
                                                <saml:Subject>
                                                        <saml:NameIdentifier>jre</saml:NameIdentifier>
                                                </saml:Subject>
                                        </saml:AuthenticationStatement>
                                        <saml:AttributeStatement>
                                                <saml:Attribute
                                                                AttributeName="role"
                                                                AttributeNamespace="oasis:names:tc:xacml:2.0:subject">
                                                        <saml:AttributeValue>weboamadmin</saml:AttributeValue>
                                                </saml:Attribute>
                                        </saml:AttributeStatement>
                                </saml:Assertion>

                        </samlp:Response>
                </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>
m_pXmlXPathObject=xmlxpathValExpression((xmlChar*)pszXPathQuery,m_pXmlXPathContext)

                                <saml:Assertion MajorVersion="1"
                                                        MinorVersion="1"
                                                        AssertionID="_a75adf55-01d7-40cc-929f-dbd8372ebdfc"
                                                        Issuer="SAML_AUTH_URI"
                                                        IssueInstant="2005-06-08T12:00:01.100Z">
                                        <saml:AuthenticationStatement
                                                        AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
                                                        AuthenticationInstant="2005-06-08T11:59:59.000Z">
                                                <saml:Subject>
                                                        <saml:NameIdentifier>jre</saml:NameIdentifier>
                                                </saml:Subject>
                                        </saml:AuthenticationStatement>
                                        <saml:AttributeStatement>
                                                <saml:Attribute
                                                                AttributeName="role"
                                                                AttributeNamespace="oasis:names:tc:xacml:2.0:subject">
                                                        <saml:AttributeValue>weboamadmin</saml:AttributeValue>
                                                </saml:Attribute>
                                        </saml:AttributeStatement>
                                </saml:Assertion>

                        </samlp:Response>
                </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>
XML字符串

                                <saml:Assertion MajorVersion="1"
                                                        MinorVersion="1"
                                                        AssertionID="_a75adf55-01d7-40cc-929f-dbd8372ebdfc"
                                                        Issuer="SAML_AUTH_URI"
                                                        IssueInstant="2005-06-08T12:00:01.100Z">
                                        <saml:AuthenticationStatement
                                                        AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
                                                        AuthenticationInstant="2005-06-08T11:59:59.000Z">
                                                <saml:Subject>
                                                        <saml:NameIdentifier>jre</saml:NameIdentifier>
                                                </saml:Subject>
                                        </saml:AuthenticationStatement>
                                        <saml:AttributeStatement>
                                                <saml:Attribute
                                                                AttributeName="role"
                                                                AttributeNamespace="oasis:names:tc:xacml:2.0:subject">
                                                        <saml:AttributeValue>weboamadmin</saml:AttributeValue>
                                                </saml:Attribute>
                                        </saml:AttributeStatement>
                                </saml:Assertion>

                        </samlp:Response>
                </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>

jre
韦伯马明

问题在于,在执行xpath查询之前,需要注册名称空间。org网站提供了一个很好的示例,说明了如何执行此操作

                                <saml:Assertion MajorVersion="1"
                                                        MinorVersion="1"
                                                        AssertionID="_a75adf55-01d7-40cc-929f-dbd8372ebdfc"
                                                        Issuer="SAML_AUTH_URI"
                                                        IssueInstant="2005-06-08T12:00:01.100Z">
                                        <saml:AuthenticationStatement
                                                        AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
                                                        AuthenticationInstant="2005-06-08T11:59:59.000Z">
                                                <saml:Subject>
                                                        <saml:NameIdentifier>jre</saml:NameIdentifier>
                                                </saml:Subject>
                                        </saml:AuthenticationStatement>
                                        <saml:AttributeStatement>
                                                <saml:Attribute
                                                                AttributeName="role"
                                                                AttributeNamespace="oasis:names:tc:xacml:2.0:subject">
                                                        <saml:AttributeValue>weboamadmin</saml:AttributeValue>
                                                </saml:Attribute>
                                        </saml:AttributeStatement>
                                </saml:Assertion>

                        </samlp:Response>
                </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>

可能存在的副本
                                <saml:Assertion MajorVersion="1"
                                                        MinorVersion="1"
                                                        AssertionID="_a75adf55-01d7-40cc-929f-dbd8372ebdfc"
                                                        Issuer="SAML_AUTH_URI"
                                                        IssueInstant="2005-06-08T12:00:01.100Z">
                                        <saml:AuthenticationStatement
                                                        AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
                                                        AuthenticationInstant="2005-06-08T11:59:59.000Z">
                                                <saml:Subject>
                                                        <saml:NameIdentifier>jre</saml:NameIdentifier>
                                                </saml:Subject>
                                        </saml:AuthenticationStatement>
                                        <saml:AttributeStatement>
                                                <saml:Attribute
                                                                AttributeName="role"
                                                                AttributeNamespace="oasis:names:tc:xacml:2.0:subject">
                                                        <saml:AttributeValue>weboamadmin</saml:AttributeValue>
                                                </saml:Attribute>
                                        </saml:AttributeStatement>
                                </saml:Assertion>

                        </samlp:Response>
                </SOAP-ENV:Body>

        </SOAP-ENV:Envelope>