当前位置: 首页>>代码示例>>Python>>正文


Python XPathQuery.queryForString方法代码示例

本文整理汇总了Python中twisted.words.xish.xpath.XPathQuery.queryForString方法的典型用法代码示例。如果您正苦于以下问题:Python XPathQuery.queryForString方法的具体用法?Python XPathQuery.queryForString怎么用?Python XPathQuery.queryForString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.words.xish.xpath.XPathQuery的用法示例。


在下文中一共展示了XPathQuery.queryForString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_queryForString

# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import queryForString [as 别名]
 def test_queryForString(self):
     """
     Test for queryForString and queryForStringList.
     """
     xp = XPathQuery("/foo")
     self.assertEquals(xp.queryForString(self.e), "somecontent")
     self.assertEquals(xp.queryForStringList(self.e), ["somecontent", "somemorecontent"])
开发者ID:RockySteveJobs,项目名称:python-for-android,代码行数:9,代码来源:test_xpath.py

示例2: testFunctionality

# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import queryForString [as 别名]
    def testFunctionality(self):
        xp = XPathQuery("/foo/bar")
        self.assertEquals(xp.matches(self.e), 1)

        xp = XPathQuery("/foo/bar/foo")
        self.assertEquals(xp.matches(self.e), 1)
        self.assertEquals(xp.queryForNodes(self.e), [self.subfoo])
        
        xp = XPathQuery("/foo/bar3")
        self.assertEquals(xp.matches(self.e), 0)

        xp = XPathQuery("/foo/*")
        self.assertEquals(xp.matches(self.e), True)
        self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4])

        xp = XPathQuery("/foo[@attrib1]")
        self.assertEquals(xp.matches(self.e), True)

        xp = XPathQuery("/foo/*[@attrib2='value2']")
        self.assertEquals(xp.matches(self.e), True)
        self.assertEquals(xp.queryForNodes(self.e), [self.bar2])

# XXX: Revist this, given new grammar
#        xp = XPathQuery("/foo/bar[2]")
#        self.assertEquals(xp.matches(self.e), 1)
#        self.assertEquals(xp.queryForNodes(self.e), [self.bar1])

        xp = XPathQuery("/foo[@xmlns='testns']/bar")
        self.assertEquals(xp.matches(self.e), 1)

        xp = XPathQuery("/foo[@xmlns='badns']/bar2")
        self.assertEquals(xp.matches(self.e), 0)

        xp = XPathQuery("/foo[@attrib1='value1']")
        self.assertEquals(xp.matches(self.e), 1)

        xp = XPathQuery("/foo")
        self.assertEquals(xp.queryForString(self.e), "somecontent")
        self.assertEquals(xp.queryForStringList(self.e), ["somecontent", "somemorecontent"])

        xp = XPathQuery("/foo/bar")
        self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar4])

        xp = XPathQuery("/foo[text() = 'somecontent']")
        self.assertEquals(xp.matches(self.e), True)

        xp = XPathQuery("/foo[not(@nosuchattrib)]")
        self.assertEquals(xp.matches(self.e), True)

        xp = XPathQuery("//gar")
        self.assertEquals(xp.matches(self.e), True)
        self.assertEquals(xp.queryForNodes(self.e), [self.gar1, self.gar2])
        self.assertEquals(xp.queryForStringList(self.e), ["DEF", "ABC"])

        xp = XPathQuery("//bar")
        self.assertEquals(xp.matches(self.e), True)
        self.assertEquals(xp.queryForNodes(self.e), [self.bar1, self.bar2, self.bar3, self.bar4])
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:59,代码来源:test_xpath.py

示例3: test_queryForString

# 需要导入模块: from twisted.words.xish.xpath import XPathQuery [as 别名]
# 或者: from twisted.words.xish.xpath.XPathQuery import queryForString [as 别名]
 def test_queryForString(self):
     """
     queryforString on absolute paths returns their first CDATA.
     """
     xp = XPathQuery("/foo")
     self.assertEqual(xp.queryForString(self.e), "somecontent")
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:8,代码来源:test_xpath.py


注:本文中的twisted.words.xish.xpath.XPathQuery.queryForString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。