이 xml을 사용하여 xsd를 준비하고 행을 더 처리하여 데이터를 데이터베이스에 삽입하려고합니다. xsd를 준비하기 위해 xslt를 사용하여 구조를 원하는 형식으로 변환합니다.노드 값에 url이 포함되어있는 경우 XML 노드를 제거하는 방법은 무엇입니까?
<linked-hash-map>
<entry>
<string>_type</string>
<string>News</string>
</entry>
<entry>
<string>value</string>
<list>
<linked-hash-map>
<entry>
<string>name</string>
<string>
Virat Kohli
</string>
</entry>
<entry>
<string>url</string>
<string>
http://www.bing.com/cr?IG=3DA864FA197A4D5DAD062780C15E3A16&CID=09E4F1057ADB64720330FB2E7BC96547&rd=1&h=nw8K4uNRgs-nvsuz2GyXpqMxdRmzWK8Xbm3W_1IlO24&v=1&r=http%3a%2f%2fmovies.ndtv.com%2fbollywood%2fvirat-kohli-hearts-anushka-sharma-a-timeline-of-their-romance-1659877&p=DevEx,5026.1
</string>
</entry>
<entry>
<string>image</string>
<linked-hash-map>
<entry>
<string>thumbnail</string>
<linked-hash-map>
<entry>
<string>contentUrl</string>
<string>
https://www.bing.com/th?id=ON.EE674002EC235BD5795D34695EABF504&pid=News
</string>
</entry>
<entry>
<string>width</string>
<int>640</int>
</entry>
</linked-hash-map>
</entry>
</linked-hash-map>
</entry>
<entry>
<string>description</string>
<string>
On Wednesday, cricketer Virat Kohli
</string>
</entry>
<entry>
<string>datePublished</string>
<string>2017-02-16T05:39:00</string>
</entry>
<entry>
<string>category</string>
<string>Entertainment</string>
</entry>
</linked-hash-map>
<linked-hash-map>
<entry>
<string>name</string>
<string>
Shah Rukh Khan’s TV show
</string>
</entry>
<entry>
<string>url</string>
<string>
http://www.bing.com/cr?IG=3DA864FA197A4D5DAD062780C15E3A16&CID=09E4F1057ADB64720330FB2E7BC96547&rd=1&h=4CnQhOg9Nm7pmIu9OvDl6x9WtYtSuXblCSR_WQz1VoA&v=1&r=http%3a%2f%2fwww.hindustantimes.com%2ftv%2fshah-rukh-khan-s-tv-show-circus-is-back-on-small-screen%2fstory-OjQUQIWi6ogxj5eF1hivTI.html&p=DevEx,5040.1
</string>
</entry>
<entry>
<string>image</string>
<linked-hash-map>
<entry>
<string>thumbnail</string>
<linked-hash-map>
<entry>
<string>contentUrl</string>
<string>
https://www.bing.com/th?id=ON.2974262BB8317FA4D4BCE4A61CA9488E&pid=News
</string>
</entry>
<entry>
<string>width</string>
<int>700</int>
</entry>
</linked-hash-map>
</entry>
</linked-hash-map>
</entry>
<entry>
<string>description</string>
<string>
Here’s some wonderful news
</string>
</entry>
<entry>
<string>datePublished</string>
<string>2017-02-16T05:36:00</string>
</entry>
<entry>
<string>category</string>
<string>Entertainment</string>
</entry>
</linked-hash-map>
</list>
</entry>
</linked-hash-map>
여기 URL에 쿼리 문자열이 있습니다. 어떻게 URL을 제거하는 방법 또는 querystring과 함께 URL을 인코딩하는 방법?
원하는 출력 아래
<?xml version="1.0" encoding="utf-8"?>
<linked-hash-map>
<entry>
<linked-hash-map>
<_type>News</_type>
<datarow>
<name> Virat Kohli</name>
<url>http://www.bing.com/cr?IG=3DA864FA197A4D5DAD062780C15E3A16&CID=09E4F1057ADB64720330FB2E7BC96547&rd=1&h=nw8K4uNRgs-nvsuz2GyXpqMxdRmzWK8Xbm3W_1IlO24&v=1&r=http%3a%2f%2fmovies.ndtv.com%2fbollywood%2fvirat-kohli-hearts-anushka-sharma-a-timeline-of-their-romance-1659877&p=DevEx,5026.1</url>
<contentUrl> https://www.bing.com/th?id=ON.EE674002EC235BD5795D34695EABF504&pid=News </contentUrl>
<width>640</width>
<description> On Wednesday, cricketer Virat Kohli</description>
<readLink> https://api.cognitive.microsoft.com/api/v5/entities/b8ef6b82-02be-1e24-584c-f8283b7bdaeb </readLink>
<datePublished>2017-02-16T05:39:00</datePublished>
<category>Entertainment</category>
</datarow>
<datarow>
<name> Shah Rukh Khan’s TV show</name>
<url> http://www.bing.com/cr?IG=3DA864FA197A4D5DAD062780C15E3A16&CID=09E4F1057ADB64720330FB2E7BC96547&rd=1&h=4CnQhOg9Nm7pmIu9OvDl6x9WtYtSuXblCSR_WQz1VoA&v=1&r=http%3a%2f%2fwww.hindustantimes.com%2ftv%2fshah-rukh-khan-s-tv-show-circus-is-back-on-small-screen%2fstory-OjQUQIWi6ogxj5eF1hivTI.html&p=DevEx,5040.1 </url>
<contentUrl> https://www.bing.com/th?id=ON.EE674002EC235BD5795D34695EABF504&pid=News </contentUrl>
<width>640</width>
<description> Here’s some wonderful news </description>
<readLink> https://api.cognitive.microsoft.com/api/v5/entities/b8ef6b82-02be-1e24-584c-f8283b7bdaeb </readLink>
<datePublished>2017-02-16T05:39:00</datePublished>
<category>Entertainment</category>
</datarow>
</linked-hash-map>
</entry>
</linked-hash-map>
제가 이러한 구조를 변환하는 데 사용되는 스크립트이다. URL에 사용되는 앰퍼샌드 XML entity references, 즉 &
해당로 교체해야합니다으로
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/linked-hash-map">
<xsl:element name="{local-name()}">
<xsl:for-each select="entry">
<xsl:choose>
<xsl:when test="list/linked-hash-map">
<xsl:for-each select="list/linked-hash-map">
<datarow>
<xsl:for-each select="entry">
<xsl:if test="not(node()[1]='image' or node()[1]='about' or node()[1]='clusteredArticles' or node()[1]='mentions' or node()[1]='provider' or node()[1]='url' or node()[1]='description' or node()[1]='name')">
<xsl:text disable-output-escaping="yes"><</xsl:text>
<xsl:value-of select="*[1]"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:value-of select="*[2]"/>
<xsl:text disable-output-escaping="yes"></</xsl:text>
<xsl:value-of select="*[1]"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:if>
</xsl:for-each>
</datarow>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:text disable-output-escaping="yes"><</xsl:text>
<xsl:value-of select="*[1]"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:value-of select="*[2]"/>
<xsl:text disable-output-escaping="yes"></</xsl:text>
<xsl:value-of select="*[1]"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="/">
<xsl:copy>
<linked-hash-map>
<entry>
<xsl:apply-templates/>
</entry>
</linked-hash-map>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
시도한 스크립트는 어디에 있습니까? 어떤 오류나 바람직하지 않은 결과가 있습니까? – Parfait
처음에는 스크립트 자체가 실행되는 동안 자체 실패. 앞으로 이동하려면 Java 코드를 통해 & 기호를 조작하고 공백으로 바꾼다. 나는 게시물을 업데이트했다. 상기 참조하십시오. – user3187932