Вы можете использовать is(':visible');
в jquery И для $ ('. item: hover') он также работает в JQuery.
это htm-код snnipet:
<li class="item-109 deeper parent">
<a class="root" href="/Comsopolis/index.php/matiers"><span>Matiers</span></a>
<ul>
<li class="item-110 noAff">
<a class=" item sousMenu" href="/Comsopolis/index.php/matiers/tsdi">
<span>Tsdi</span>
</a>
</li>
<li class="item-111 noAff">
<a class="item" href="/Comsopolis/index.php/matiers/reseaux">
<span>Réseaux</span>
</a>
</li>
</ul>
</li>
, и это код JS:
$('.menutop > li').hover(function() {//,.menutop li ul
$(this).find('ul').show('fast');
},function() {
if($(this).find('ul').is(':hover'))
$(this).hide('fast');
});
$('.root + ul').mouseleave(function() {
if($(this).is(':visible'))
$(this).hide('fast');
});
это то, о чем я говорил:)
import xml.dom.minidom
dom = xml.dom.minidom.parse(xml_fname) # or xml.dom.minidom.parseString(xml_string)
pretty_xml_as_string = dom.toprettyxml()
Можно попробовать это изменение...
Установка BeautifulSoup
и бэкенд lxml
(синтаксический анализатор) библиотеки:
user$ pip3 install lxml bs4
Процесс Ваш XML-документ:
from bs4 import BeautifulSoup
with open('/path/to/file.xml', 'r') as doc:
for line in doc:
print(BeautifulSoup(line, 'lxml').prettify())
XML pretty print for python looks pretty good for this task. (Appropriately named, too.)
An alternative is to use pyXML, which has a PrettyPrint function.
Если вы используете реализацию DOM, у каждого есть своя собственная форма встроенной симпатичной печати:
# minidom
#
document.toprettyxml()
# 4DOM
#
xml.dom.ext.PrettyPrint(document, stream)
# pxdom (or other DOM Level 3 LS-compliant imp)
#
serializer.domConfig.setParameter('format-pretty-print', True)
serializer.writeToString(document)
Если вы используете что-то другое без собственного симпатичного принтера - или эти симпатичные принтеры делают это не совсем так, как вы хотите - вам, вероятно, придется написать или создать подкласс своего собственного сериализатора.
lxml недавно обновлен и включает в себя симпатичную функцию печати
import lxml.etree as etree
x = etree.parse("filename")
print etree.tostring(x, pretty_print=True)
Ознакомьтесь с руководством по lxml: http://lxml.de/tutorial.html
У меня были проблемы с красивой печатью минидома. Я получал UnicodeError всякий раз, когда пытался распечатать документ с символами вне заданной кодировки, например, если бы у меня был β в документе, и я попробовал doc.toprettyxml (encoding = 'latin-1')
. Вот мой способ решения этой проблемы:
def toprettyxml(doc, encoding):
"""Return a pretty-printed XML document in a given encoding."""
unistr = doc.toprettyxml().replace(u'<?xml version="1.0" ?>',
u'<?xml version="1.0" encoding="%s"?>' % encoding)
return unistr.encode(encoding, 'xmlcharrefreplace')
from lxml import etree
import xml.dom.minidom as mmd
xml_root = etree.parse(xml_fiel_path, etree.XMLParser())
def print_xml(xml_root):
plain_xml = etree.tostring(xml_root).decode('utf-8')
urgly_xml = ''.join(plain_xml .split())
good_xml = mmd.parseString(urgly_xml)
print(good_xml.toprettyxml(indent=' ',))
Это работает хорошо на xml с китайским языком!
Вот мое (халтурное?) решение, чтобы обойти проблему уродливого текстового узла.
uglyXml = doc.toprettyxml(indent=' ')
text_re = re.compile('>\n\s+([^<>\s].*?)\n\s+</', re.DOTALL)
prettyXml = text_re.sub('>\g<1></', uglyXml)
print prettyXml
Приведенный выше код даст:
<?xml version="1.0" ?>
<issues>
<issue>
<id>1</id>
<title>Add Visual Studio 2005 and 2008 solution files</title>
<details>We need Visual Studio 2005/2008 project files for Windows.</details>
</issue>
</issues>
Вместо этого:
<?xml version="1.0" ?>
<issues>
<issue>
<id>
1
</id>
<title>
Add Visual Studio 2005 and 2008 solution files
</title>
<details>
We need Visual Studio 2005/2008 project files for Windows.
</details>
</issue>
</issues>
Отказ от ответственности: Возможно, есть некоторые ограничения.