targetNamespace的又一次理解

本文详细解释了XML Schema中targetNamespace属性的作用,包括如何为自定义元素定义命名空间,并通过实例展示了不同XML文件间如何引用这些命名空间内的元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

targetNamespace是一个xml的schema中的概念 
比如我们定义了这么个schema: 
<xs:schema   xmlns:xs= "http://www.w3.org/2001/XMLSchema " 
                      targetNamespace= "http://a.name/space "> 
<xs:element   name= "address "   type= "xs:string "   /> 
</xs:schema> 

那么它表示的意思是address这个元素是属于 "http://a.name/space "命名空间的。你想想看,如果你不指定targetNamespace,那么address是属于什么命名空间是不知道的,它肯定不是属于“http://www.w3.org/2001/XMLSchema”命名空间。指定了这个以后,就能让我们定义的schema中的元素都有自己的命名空间。这个命名空间都是自己定义的。

我想targetNamespace= "http://a.name/space "就是为你自己定义的元素定义了一个包,也就是package的概念,你的这个元素是这个package(命名空间)里的,在别的XML文件里面你可以用<xs:schema xmlns:s= "http://a.name/space" />来引用你前面定义的元素,这里就相当于import的概念了。

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" 

targetNamespace="http://www.cfx.com"

xmlns="http://www.cfx.com" 

attributeFormDefault="unqualified">

<xs:element name="person">

 <xs:complexType>

           <xs:sequence>

             <xs:element name="name" type="xs:string"></xs:element>           

           </xs:sequence>  

 </xs:complexType>

</xs:element>

 

</xs:schema>

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" 

 targetNamespace="http://www.a.com"

 xmlns="http://www.a.com"

attributeFormDefault="unqualified">

<xs:element name="teacher">

<xs:complexType>

            <xs:sequence>

                <xs:element name="address" type="xs:string"></xs:element>            

            </xs:sequence>

</xs:complexType>

</xs:element>

 

</xs:schema>

 

 

<?xml version="1.0" encoding="UTF-8"?>

<person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xmlns:xsn="http://www.a.com"

xsi:schemaLocation="http://www.a.com  test_targetNamespace.xsd

http://www.a.com test_any_10.xsd

" xmlns="http://www.a.com">

<student>杨凯</student>

<xsn:teacher>

        <xsn:address>山东省济南市</xsn:address>

</xsn:teacher>

 

</person>

 

 

 

 

@Override public List<Map<String,String>> findReturnTaskList(WfTaskBo bo) { // 当前任务 task Task task = taskService.createTaskQuery().taskId(bo.getTaskId()).singleResult(); // 获取流程定义信息 ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult(); // 获取流程模型信息 ModelInstance bpmnModel = repositoryService.getBpmnModelInstance(processDefinition.getId()); // 查询历史节点实例 List<HistoricActivityInstance> activityInstanceList = historyService.createHistoricActivityInstanceQuery() .processInstanceId(task.getProcessInstanceId()) .activityType("userTask") .finished() .orderByHistoricActivityInstanceEndTime().asc() .list(); List<String> activityIdList = activityInstanceList.stream() .map(HistoricActivityInstance::getActivityId) .filter(activityId -> !StringUtils.equals(activityId, task.getTaskDefinitionKey())) .distinct() .collect(Collectors.toList()); // 获取当前任务节点元素 FlowElement source = ModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey()); ArrayList<Map<String,String>> list = new ArrayList<>(); for (String activityId : activityIdList) { FlowElement target = ModelUtils.getFlowElementById(bpmnModel, activityId); boolean isSequential = ModelUtils.isSequentialReachable(source, target, new HashSet<>()); if (isSequential) { HashMap<String, String> map = new HashMap<>(); map.put("id",target.getId()); map.put("name",target.getName()); list.add(map); } } return list; }public static boolean isSequentialReachable(FlowElement source, FlowElement target, Set<String> visitedElements) { visitedElements = visitedElements == null ? new HashSet<>() : visitedElements; if (source instanceof StartEvent && isInEventSubprocess(source)) { return false; } // 根据类型,获取入口连线 List<SequenceFlow> sequenceFlows = FlowableUtils.getElementIncomingFlows(source); if (sequenceFlows != null && sequenceFlows.size() > 0) { // 循环找到目标元素 for (SequenceFlow sequenceFlow: sequenceFlows) { // 如果发现连线重复,说明循环了,跳过这个循环 if (visitedElements.contains(sequenceFlow.getId())) { continue; } // 添加已经走过的连线 visitedElements.add(sequenceFlow.getId()); FlowElement sourceFlowElement = sequenceFlow.getSource(); // 这条线路存在目标节点,这条线路完成,进入下个线路 if (target.getId().equals(sourceFlowElement.getId())) { continue; } // 如果目标节点为并行网关,则不继续 if (sourceFlowElement instanceof ParallelGateway) { return false; } // 否则就继续迭代 boolean isSequential = isSequentialReachable(sourceFlowElement, target, visitedElements); if (!isSequential) { return false; } } } return true; }<?xml version="1.0" encoding="UTF-8"?> <bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="diagram_Process_1753668224965" targetNamespace="http://bpmn.io/schema/bpmn" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"> <bpmn2:process id="Process_1753668224965" name="退回测试-1753668224965" isExecutable="true"> <bpmn2:startEvent id="Event_07cxhwn"> <bpmn2:outgoing>Flow_13no8c4</bpmn2:outgoing> </bpmn2:startEvent> <bpmn2:userTask id="Activity_07rwlk4" name="组长" camunda:candidateGroups="ROLE1"> <bpmn2:extensionElements> <camunda:property name="dataType" value="ROLES" /> </bpmn2:extensionElements> <bpmn2:incoming>Flow_13no8c4</bpmn2:incoming> <bpmn2:outgoing>Flow_1yumrqn</bpmn2:outgoing> </bpmn2:userTask> <bpmn2:sequenceFlow id="Flow_13no8c4" sourceRef="Event_07cxhwn" targetRef="Activity_07rwlk4" /> <bpmn2:userTask id="Activity_1y4mib6" name="项目经理" camunda:candidateGroups="ROLE1"> <bpmn2:extensionElements> <camunda:property name="dataType" value="ROLES" /> </bpmn2:extensionElements> <bpmn2:incoming>Flow_1yumrqn</bpmn2:incoming> <bpmn2:outgoing>Flow_0bwcnie</bpmn2:outgoing> </bpmn2:userTask> <bpmn2:sequenceFlow id="Flow_1yumrqn" sourceRef="Activity_07rwlk4" targetRef="Activity_1y4mib6" /> <bpmn2:userTask id="Activity_0j6zhl7" name="hr人事" camunda:candidateGroups="ROLE1"> <bpmn2:extensionElements> <camunda:property name="dataType" value="ROLES" /> </bpmn2:extensionElements> <bpmn2:incoming>Flow_0bwcnie</bpmn2:incoming> <bpmn2:outgoing>Flow_19w3spj</bpmn2:outgoing> </bpmn2:userTask> <bpmn2:sequenceFlow id="Flow_0bwcnie" sourceRef="Activity_1y4mib6" targetRef="Activity_0j6zhl7" /> <bpmn2:sequenceFlow id="Flow_19w3spj" sourceRef="Activity_0j6zhl7" targetRef="Event_06m1fk6" /> <bpmn2:endEvent id="Event_06m1fk6"> <bpmn2:incoming>Flow_19w3spj</bpmn2:incoming> </bpmn2:endEvent> </bpmn2:process> <bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1753668224965"> <bpmndi:BPMNEdge id="Flow_13no8c4_di" bpmnElement="Flow_13no8c4"> <di:waypoint x="328" y="370" /> <di:waypoint x="380" y="370" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="Flow_1yumrqn_di" bpmnElement="Flow_1yumrqn"> <di:waypoint x="480" y="370" /> <di:waypoint x="540" y="370" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="Flow_0bwcnie_di" bpmnElement="Flow_0bwcnie"> <di:waypoint x="640" y="370" /> <di:waypoint x="700" y="370" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="Flow_19w3spj_di" bpmnElement="Flow_19w3spj"> <di:waypoint x="800" y="370" /> <di:waypoint x="872" y="370" /> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="Event_07cxhwn_di" bpmnElement="Event_07cxhwn"> <dc:Bounds x="292" y="352" width="36" height="36" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="Activity_07rwlk4_di" bpmnElement="Activity_07rwlk4"> <dc:Bounds x="380" y="330" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="Activity_1y4mib6_di" bpmnElement="Activity_1y4mib6"> <dc:Bounds x="540" y="330" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="Activity_0j6zhl7_di" bpmnElement="Activity_0j6zhl7"> <dc:Bounds x="700" y="330" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="Event_06m1fk6_di" bpmnElement="Event_06m1fk6"> <dc:Bounds x="872" y="352" width="36" height="36" /> </bpmndi:BPMNShape> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </bpmn2:definitions> 我的方法有问题,现在我回退了几次节点,我第一次hr回退到了组长审批,为什么组长那个位置回退还是会有hr的回退节点
最新发布
07-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值