Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
swiftMtMx
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
isc-v3.1-tmp
swiftMtMx
Commits
0058d1ce
Commit
0058d1ce
authored
Oct 14, 2022
by
chengzhuoshen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
有命名空间的xml代码解析,增加去掉命名空间的代码
parent
c8d7ade9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
1 deletions
+47
-1
pom.xml
pom.xml
+1
-1
Mx2ElementCreatorManager.java
...brilliance/swift/mx2element/Mx2ElementCreatorManager.java
+7
-0
XmlUtil.java
...Core/src/main/java/com/brilliance/swift/util/XmlUtil.java
+39
-0
No files found.
pom.xml
View file @
0058d1ce
...
...
@@ -43,7 +43,7 @@
<dependency>
<groupId>
dom4j
</groupId>
<artifactId>
dom4j
</artifactId>
<version>
1.1
</version>
<version>
1.
6.
1
</version>
</dependency>
<dependency>
<groupId>
javax.validation
</groupId>
...
...
swiftCore/src/main/java/com/brilliance/swift/mx2element/Mx2ElementCreatorManager.java
View file @
0058d1ce
...
...
@@ -8,6 +8,8 @@ import com.brilliance.swift.mx2element.camt054001.Mx2ElementCamt054001Creator;
import
com.brilliance.swift.mx2element.camt056001.Mx2ElementCamt056001Creator
;
import
com.brilliance.swift.mx2element.pacs008001.Mx2ElementPacs008001Creator
;
import
com.brilliance.swift.mx2element.pacs009001.Mx2ElementPacs009001Creator
;
import
com.brilliance.swift.util.StringUtil
;
import
com.brilliance.swift.util.XmlUtil
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.prowidesoftware.swift.model.mx.AbstractMX
;
...
...
@@ -40,6 +42,11 @@ public class Mx2ElementCreatorManager {
public
Map
<
String
,
Object
>
mx2ElementMaps
(
String
xmlStr
)
throws
SwiftException
{
xmlStr
=
handlingXml
(
xmlStr
);
AbstractMX
abstractMX
=
AbstractMX
.
parse
(
xmlStr
);
//如果存在命名空間則去掉命名空間 重新parse
if
(
StringUtil
.
isEmpty
(
abstractMX
.
getAppHdr
().
from
()))
{
xmlStr
=
XmlUtil
.
clearXmlNamespace
(
xmlStr
);
abstractMX
=
AbstractMX
.
parse
(
xmlStr
);
}
String
messageType
=
(
abstractMX
.
getMxId
().
getBusinessProcess
().
name
()
+
"."
+
abstractMX
.
getMxId
().
getFunctionality
()
...
...
swiftCore/src/main/java/com/brilliance/swift/util/XmlUtil.java
View file @
0058d1ce
package
com
.
brilliance
.
swift
.
util
;
import
com.brilliance.swift.exception.SwiftException
;
import
org.dom4j.*
;
import
org.dom4j.io.SAXReader
;
import
org.dom4j.tree.DefaultElement
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.net.URL
;
import
java.util.HashMap
;
...
...
@@ -184,4 +187,40 @@ public class XmlUtil {
}
}
public
static
String
clearXmlNamespace
(
String
xmlStr
)
{
try
{
SAXReader
reader
=
new
SAXReader
();
Document
document
=
reader
.
read
(
new
ByteArrayInputStream
(
xmlStr
.
getBytes
()));
document
.
accept
(
new
NameSpaceCleaner
());
String
xml
=
document
.
asXML
();
return
xml
.
replaceAll
(
"xmlns:([\\w]*)"
,
"xmlns"
);
}
catch
(
DocumentException
e
)
{
throw
new
SwiftException
(
e
.
getMessage
());
}
}
private
static
class
NameSpaceCleaner
extends
VisitorSupport
{
public
void
visit
(
Document
document
)
{
((
DefaultElement
)
document
.
getRootElement
())
.
setNamespace
(
Namespace
.
NO_NAMESPACE
);
document
.
getRootElement
().
additionalNamespaces
().
clear
();
}
public
void
visit
(
Namespace
namespace
)
{
namespace
.
detach
();
}
public
void
visit
(
Attribute
node
)
{
if
(
node
.
toString
().
contains
(
"xmlns"
)
||
node
.
toString
().
contains
(
"xsi:"
))
{
node
.
detach
();
}
}
public
void
visit
(
Element
node
)
{
if
(
node
instanceof
DefaultElement
)
{
((
DefaultElement
)
node
).
setNamespace
(
Namespace
.
NO_NAMESPACE
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment