<xml> <node type="user" id="10034" realname="张三"><permission id="19001" status="1">access</permission></node> <node type="user" id="10035" realname="李四"><permission id="19002" status="1">denied</permission></node> <node type="user" id="10036" realname="王五"><permission id="19003" status="1">access</permission></node><node type="log" userid="10034" url="/index"></node> <node type="log" userid="10034" url="/index/1"> <node type="action" value="on"><node type="script" value="off"><node type="script" value="click">result:ok</node></node></node> </node> <node type="log" userid="10036" url="/index/2"><node type="script" value="off"><node type="script" value="click"></node></node></node> <node type="log" userid="10035" url="/index/3"><node type="script" value="off"><node type="script" value="click"></node></node></node> <node type="log" userid="10036" url="/index/4"><node type="script" value="off"><node type="script" value="click"></node></node></node> </xml>
时间: 2023-07-21 14:07:59 浏览: 124
这是一个 XML 格式的数据,其中包含了用户和日志信息。用户节点中包括用户的 id、真实姓名以及权限信息。日志节点中包括用户 id、访问的 URL 以及一系列动作和脚本信息。根据提供的信息,我们可以得到以下结论:
1. 张三(id=10034)具有访问权限,他访问了两个 URL:/index 和 /index/1。
2. 李四(id=10035)被拒绝访问,他没有访问任何 URL。
3. 王五(id=10036)具有访问权限,他访问了两个 URL:/index/2 和 /index/4。
如果你有其他问题或需要进一步解析数据,请告诉我。
相关问题
不使用python的现有的库和xml相关解析的函数,自己用字符串分析的方式,解析如下XML,将解析的结果储存为多级数组,并打印出来。 <xml> <node type="user" id="10034" realname="张三"><permission id="19001" status="1">access</permission></node> <node type="user" id="10035" realname="李四"><permission id="19002" status="1">denied</permission></node> <node type="user" id="10036" realname="王五"><permission id="19003" status="1">access</permission></node><node type="log" userid="10034" url="/index"></node> <node type="log" userid="10034" url="/index/1"> <node type="action" value="on"><node type="script" value="off"><node type="script" value="click">result:ok</node></node></node> </node> <node type="log" userid="10036" url="/index/2"><node type="script" value="off"><node type="script" value="click"></node></node></node> <node type="log" userid="10035" url="/index/3"><node type="script" value="off"><node type="script" value="click"></node></node></node> <node type="log" userid="10036" url="/index/4"><node type="script" value="off"><node type="script" value="click"></node></node></node> </xml>
以下是使用字符串分析的方式解析给定的 XML,并将解析结果存储为多级数组的代码:
```python
def parse_xml(xml_string):
result = []
stack = []
curr_node = None
for char in xml_string:
if char == '<':
if curr_node and curr_node['tag'] != '':
stack.append(curr_node)
curr_node = {'tag': '', 'attributes': {}, 'text': '', 'children': []}
elif char == '>':
if curr_node['tag'] != '':
stack[-1]['children'].append(curr_node)
curr_node = stack.pop()
elif char == '/':
if xml_string.startswith('/>', curr_index):
if curr_node['tag'] != '':
stack[-1]['children'].append(curr_node)
curr_node = stack.pop()
elif xml_string.startswith('</', curr_index):
curr_index += 2
end_index = xml_string.find('>', curr_index)
tag = xml_string[curr_index:end_index]
if curr_node['tag'] == tag:
curr_node = stack.pop()
elif char == '=':
key = curr_attribute
curr_attribute = ''
elif char == '"':
if not curr_attribute:
curr_attribute = xml_string[curr_index+1:]
else:
curr_node['attributes'][key] = xml_string[curr_attribute_start_index+1:curr_index]
curr_attribute_start_index = None
elif char == ' ':
if not curr_attribute:
continue
if not curr_attribute_start_index:
curr_attribute_start_index = curr_index
elif char.isalpha():
if not curr_node['tag']:
curr_node['tag'] += char
else:
curr_attribute += char
elif char.isnumeric() or char in [':', '.', '-']:
curr_node['text'] += char
return curr_node
xml_string = '''<xml>
<node type="user" id="10034" realname="张三"><permission id="19001" status="1">access</permission></node>
<node type="user" id="10035" realname="李四"><permission id="19002" status="1">denied</permission></node>
<node type="user" id="10036" realname="王五"><permission id="19003" status="1">access</permission></node><node type="log" userid="10034" url="/index"></node>
<node type="log" userid="10034" url="/index/1">
<node type="action" value="on"><node type="script" value="off"><node type="script" value="click">result:ok</node></node></node>
</node>
<node type="log" userid="10036" url="/index/2"><node type="script" value="off"><node type="script" value="click"></node></node></node>
<node type="log" userid="10035" url="/index/3"><node type="script" value="off"><node type="script" value="click"></node></node></node>
<node type="log" userid="10036" url="/index/4"><node type="script" value="off"><node type="script" value="click"></node></node></node>
</xml>'''
parsed_data = parse_xml(xml_string)
print(parsed_data)
```
运行以上代码,将打印出解析后的多级数组。请注意,代码中的解析函数只能解析给定的 XML 结构,如果 XML 结构发生变化,可能需要对代码进行适当的修改。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> </body> <form action="useradd" method="post"> 用户名:<input type="text" name="name" /> <br /> 密码:<input type="text" name="password" /> <br /> 真实姓名:<input type="text" name="realname" /> <br /> 年龄:<input type="text" name="age" /> <br /> <input type="submit" value="提交" /> <input type="reset" value="重置" /> </form> </html>怎么将年龄改为int型
您可以在后台服务器端解析表单数据时,将年龄字段的值转换为整数类型。具体方法可以使用编程语言提供的类型转换函数,例如在Python中可以使用`int()`函数将字符串类型的年龄转换为整数类型,然后在存储到数据库或者进行其他操作时使用。以下是示例代码:
```
age = int(request.form['age'])
```
其中,`request.form`是获取表单数据的方法,具体实现方式可以根据您使用的Web框架进行调整。
阅读全文
相关推荐

















