简体   繁体   中英

I have two <?xml version=“1.0” encoding=“UTF-8”?> tags in one xml file and I'm trying to create a xslt for it, How do i handle these tags?

I need to create a XSLT code for this but after reaching 'Response' code fails. And since I'm receiving it from remote service I can not change it. Please give some suggestions for the same. XML that I'm receiving in response:

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Response><?xml version="1.0" encoding="UTF-8"?>
<ResponseCode>
0
</ResponseCode>
</Response>
</soapenv:Body>
</soapenv:Envelope>

If you have two XML declarations in a file then your file is not XML, and if it is not XML then it cannot be processed using XSLT.

If you want to process non-XML files then you will need to use some non-XML technology to convert them to XML before you start. (However, it's best to try and persuade the supplier to fix their bug if you can. The whole point about standards is that they save costs for everyone provided you actually follow the rules.) If you do need to repair broken XML files, you can sometimes use a utility such as HTML Tidy or validator.nu, or you may need a custom Perl script or similar.

LATER

Actually, I think I should qualify this answer. If you know that your file contains a sequence of well-formed XML documents, each starting with an XML declaration, then it might be feasible to read it in an XSLT 3.0 stylesheet using the unparsed-text() function, split it into its constituent documents using xsl:analyze-string , parse each of those documents using the XPath 3.0 parse-xml() function, and then process the documents as normal. You would have to make sure you knew the file encoding in advance, and you would have to be confident there are no "nasties" in there, like something masquerading as an XML declaration inside a comment or CDATA section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM