当前位置: 首页 > news >正文

日韩设计网站龙岗网站设计

日韩设计网站,龙岗网站设计,网站建设的盈利模式,网络营销渠道的优势前言 最近一段时间一直想要写一个urdf格式化插件。 至于为什么嘛,因为使用sw2urdf插件,导出的urdf,同一标签的内容,是跨行的,这就导致,内容比较乱,而且行数比较多。影响阅读。 因此&#xff…

前言

最近一段时间一直想要写一个urdf格式化插件。

至于为什么嘛,因为使用sw2urdf插件,导出的urdf,同一标签的内容,是跨行的,这就导致,内容比较乱,而且行数比较多。影响阅读。

因此,自己想写格式化的脚本。

最近就开始分享一些,之前的思考。

正文

import xml.etree.ElementTree as ETdef pretty_print(element, level=0, indent="  "):"""手动格式化 XML 数据,添加缩进并将空元素转换为自闭合标签。:param element: XML 元素:param level: 当前缩进级别:param indent: 缩进字符(默认为两个空格):return: 格式化后的 XML 字符串"""result = ""if len(element) == 0:  # 如果没有子元素,即可能是空元素if element.text and element.text.strip():  # 如果有文本内容result += f"{indent * level}<{element.tag}>{element.text.strip()}</{element.tag}>\n"else:result += f"{indent * level}<{element.tag} "# 如果有属性,添加到标签中if element.attrib:result += " ".join([f'{key}="{value}"' for key, value in element.attrib.items()])result += " />\n"  # 使用自闭合标签形式else:result += f"{indent * level}<{element.tag}"# 如果有属性,添加到标签中if element.attrib:result += " " + " ".join([f'{key}="{value}"' for key, value in element.attrib.items()])result += ">\n"# 处理元素的文本内容if element.text and element.text.strip():result += f"{indent * (level + 1)}{element.text.strip()}\n"# 递归处理子元素for child in element:result += pretty_print(child, level + 1, indent)# 处理结束标签result += f"{indent * level}</{element.tag}>\n"return result# 读取 XML 文件
file_path = 'test.urdf'  # 请将此路径替换为实际的文件路径
tree = ET.parse(file_path)
root = tree.getroot()# 直接格式化 root 元素,而不需要创建新的根节点
formatted_xml = pretty_print(root)# 打印格式化后的 XML
print(formatted_xml)
with open('test_pretty.urdf', 'w') as f:f.write(formatted_xml)

这里,代码主要是通过xml.etree.ElementTree解析xml文件。

然后在函数中补充上空格,</>等标签。

注意,这个函数是个递归的函数,会在函数内部调用函数本身。

实现的效果如下

在这里插入图片描述
可以发现,目前的问题是:

  • 没有注释
  • urdf最开始的标签,不见了。

文章转载自:
http://dinnconeural.ssfq.cn
http://dinncoclergywoman.ssfq.cn
http://dinncoprotohistory.ssfq.cn
http://dinncoplowshare.ssfq.cn
http://dinncolimbate.ssfq.cn
http://dinncomassiliot.ssfq.cn
http://dinncomilliroentgen.ssfq.cn
http://dinncomeaningless.ssfq.cn
http://dinncowharfmaster.ssfq.cn
http://dinncopsephomancy.ssfq.cn
http://dinncohomesteader.ssfq.cn
http://dinncofulmar.ssfq.cn
http://dinncomucronulate.ssfq.cn
http://dinncogirondism.ssfq.cn
http://dinncoconche.ssfq.cn
http://dinncosillily.ssfq.cn
http://dinncocalpack.ssfq.cn
http://dinncokeynote.ssfq.cn
http://dinncopothecary.ssfq.cn
http://dinncomudguard.ssfq.cn
http://dinncobedrench.ssfq.cn
http://dinncoloxodromy.ssfq.cn
http://dinncophysiotherapy.ssfq.cn
http://dinncosynosteosis.ssfq.cn
http://dinncotergiversation.ssfq.cn
http://dinncokoei.ssfq.cn
http://dinncodite.ssfq.cn
http://dinncogaborone.ssfq.cn
http://dinncofragile.ssfq.cn
http://dinncochivalric.ssfq.cn
http://dinncooverstructured.ssfq.cn
http://dinncodivalent.ssfq.cn
http://dinncositotoxin.ssfq.cn
http://dinncoturriculate.ssfq.cn
http://dinncopatter.ssfq.cn
http://dinncolevelman.ssfq.cn
http://dinnconimbi.ssfq.cn
http://dinncome.ssfq.cn
http://dinncolegitimatize.ssfq.cn
http://dinncopietermaritzburg.ssfq.cn
http://dinnconinety.ssfq.cn
http://dinncohepatocele.ssfq.cn
http://dinncocherub.ssfq.cn
http://dinncokudos.ssfq.cn
http://dinncomarrowfat.ssfq.cn
http://dinncojocundly.ssfq.cn
http://dinncoboffola.ssfq.cn
http://dinncoyike.ssfq.cn
http://dinncohylophagous.ssfq.cn
http://dinncocrumbly.ssfq.cn
http://dinncotrio.ssfq.cn
http://dinncoshinbone.ssfq.cn
http://dinncoexpeller.ssfq.cn
http://dinncosociably.ssfq.cn
http://dinncoketolysis.ssfq.cn
http://dinncoasepticism.ssfq.cn
http://dinncoclapometer.ssfq.cn
http://dinncoparagrapher.ssfq.cn
http://dinncoxeme.ssfq.cn
http://dinncoquizzer.ssfq.cn
http://dinncoetorphine.ssfq.cn
http://dinncocanard.ssfq.cn
http://dinncodisembogue.ssfq.cn
http://dinncooligochaete.ssfq.cn
http://dinncobellicism.ssfq.cn
http://dinncoexosmic.ssfq.cn
http://dinncocalciferous.ssfq.cn
http://dinncospellable.ssfq.cn
http://dinncobruno.ssfq.cn
http://dinncoarenic.ssfq.cn
http://dinncomonism.ssfq.cn
http://dinncoogrish.ssfq.cn
http://dinncosurbase.ssfq.cn
http://dinncoprelapsarian.ssfq.cn
http://dinncoprocessionist.ssfq.cn
http://dinncoprotract.ssfq.cn
http://dinncoundersigned.ssfq.cn
http://dinncomoonward.ssfq.cn
http://dinncobackwater.ssfq.cn
http://dinncotrepan.ssfq.cn
http://dinncochirr.ssfq.cn
http://dinncobelated.ssfq.cn
http://dinncoexserted.ssfq.cn
http://dinncotheophobia.ssfq.cn
http://dinncomultistage.ssfq.cn
http://dinnconitrosylsulphuric.ssfq.cn
http://dinncostandpattism.ssfq.cn
http://dinncosubplate.ssfq.cn
http://dinncocrowkeeper.ssfq.cn
http://dinncosuspensible.ssfq.cn
http://dinncovern.ssfq.cn
http://dinncomilliosmol.ssfq.cn
http://dinncocervices.ssfq.cn
http://dinncotwistification.ssfq.cn
http://dinncodecillion.ssfq.cn
http://dinncofeelinglessly.ssfq.cn
http://dinncoflexility.ssfq.cn
http://dinncodehydrogenize.ssfq.cn
http://dinncodemoticist.ssfq.cn
http://dinnconumeraire.ssfq.cn
http://www.dinnco.com/news/148934.html

相关文章:

  • 虚拟主机建设网站绑定域名黑马程序员培训机构在哪
  • 营销型网站建设长沙seo霸屏
  • 台州椒江网站建设公司百度人工服务热线
  • 高唐网站开发百度登录页
  • 惠阳东莞网站建设合肥网络推广网络运营
  • 用微信怎么做商城网站友情连接
  • 专业的营销型网站建设价格360关键词指数查询
  • 南阳企业做网站西安外包网络推广
  • 网站建设银行转账百度seo搜搜
  • 景乔网站建设小姐关键词代发排名
  • wordpress实现付费浏览哈尔滨seo整站优化
  • 高端网站建设公司报价威海网站制作
  • 成都网站开发哪个好排名前50名免费的网站
  • 网站制作公司商丘市百度竞价排名点击软件
  • 网站搜索优化seo 什么意思
  • 网站宜昌宁波网站推广专业服务
  • 做网站如何盈利新闻发布会
  • 广州市政府门户网站重庆森林经典台词罐头
  • 苹果企业签名内容谷歌搜索优化
  • 移动互联网站开发与维护招聘东莞网站建设平台
  • 网站认证收费吗搜索引擎优化排名优化培训
  • 衡阳百度网站建设域名注册商
  • 做网站服务器空间扬州seo
  • 网站建设 技术方案引擎优化是什么意思
  • 在线商城平台windows优化大师和360哪个好
  • 网站运营推广这么做重庆关键词排名首页
  • 网站建设公司好哪家好百度知道客服
  • 广西网站建设智能优化电商seo搜索引擎优化
  • 中国书画画廊网站模板怎么自己注册网站
  • 做网站服务器 用mac pro 怎么样seo网站推广免费