XML

xml – Call REST Request inside XSLT and copy only some elements


I am attempting to make a REST call inside my XSL that will incorporate only parts of the response into the original transformed XML doc. I found one example that talked about using variables and the document() function, but I can’t seem to get it to work.

Here is the original XML document:

<?xml version="1.0" encoding="UTF-8"?>
<PublishPELTEST xmlns="http://www.ibm.com/maximo" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
creationDateTime="2018-02-08T09:15:08-05:00" transLanguage="EN" 
baseLanguage="EN" messageID="1518099308834189587" maximoVersion="7 5 2 12" 
event="0">
  <PELTESTSet>
    <WORKORDER>
      <DESCRIPTION>My Workorder Description</DESCRIPTION>
      <WONUM>MWO-522</WONUM>
      <WOPRIORITY>3</WOPRIORITY>
      <WORKORDERID>2255202</WORKORDERID>
      <ASSIGNMENT>
        <LABORCODE>006325</LABORCODE>
      </ASSIGNMENT>
      <KUBROUNDENTRY>
        <KUBROUNDENTRYID>267433</KUBROUNDENTRYID>
        <LINEID>254735</LINEID>
        <OBSERVATION />
        <KUBROUNDLINE>
          <ASSETNUM>385691</ASSETNUM>
          <METERNAME>VLOPSTAT</METERNAME>
          <SEQUENCE>90</SEQUENCE>
          <ASSET>
            <ASSETID>388391</ASSETID>
            <DESCRIPTION>Asset Description</DESCRIPTION>
            <SERVICEADDRESS>
              <STREETADDRESS>1234 Kingston Pike</STREETADDRESS>
            </SERVICEADDRESS>
          </ASSET>
          <METER>
            <DOMAINID>VLOPSTAT</DOMAINID>
            <METERNAME>VLOPSTAT</METERNAME>
          </METER>
        </KUBROUNDLINE>
      </KUBROUNDENTRY>
      <KUBROUNDENTRY>
        <KUBROUNDENTRYID>267432</KUBROUNDENTRYID>
        <LINEID>254734</LINEID>
        <OBSERVATION />
        <KUBROUNDLINE>
          <ASSETNUM>385691</ASSETNUM>
          <METERNAME>GLEAKGRD</METERNAME>
          <SEQUENCE>80</SEQUENCE>
          <ASSET>
            <ASSETID>388391</ASSETID>
            <DESCRIPTION>Asset2 Description</DESCRIPTION>
            <SERVICEADDRESS>
              <STREETADDRESS>2345 Kingston Pike</STREETADDRESS>
            </SERVICEADDRESS>
          </ASSET>
          <METER>
            <DOMAINID>CASEGRDE</DOMAINID>
            <METERNAME>GLEAKGRD</METERNAME>
          </METER>
        </KUBROUNDLINE>
      </KUBROUNDENTRY>
    </WORKORDER>
  </PELTESTSet>
</PublishPELTEST>

This is the REST request and the result that is returned normally:
http://server.loc.org/maxrest/rest/mbo/alndomain/?domainid=’SKIPRSN’

<?xml version="1.0" encoding="UTF-8"?>
<ALNDOMAINMboSet rsStart="0" xmlns="http://www.ibm.com/maximo" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ALNDOMAIN xmlns="http://www.ibm.com/maximo" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <DOMAINID>KUBSKIPRSN</DOMAINID>
        <VALUE>TRAFFIC</VALUE>
        <DESCRIPTION>Traffic Control Needed</DESCRIPTION>
        <ALNDOMAINID>4906</ALNDOMAINID>
        <VALUEID>KUBSKIPRSN|TRAFFIC</VALUEID>
    </ALNDOMAIN>
    <ALNDOMAIN xmlns="http://www.ibm.com/maximo" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <DOMAINID>KUBSKIPRSN</DOMAINID>
        <VALUE>NOT FOUND</VALUE>
        <DESCRIPTION>Asset Not Found</DESCRIPTION>
        <ALNDOMAINID>4006</ALNDOMAINID>
        <VALUEID>KUBSKIPRSN|NOT FOUND</VALUEID>
    </ALNDOMAIN>
    <ALNDOMAIN xmlns="http://www.ibm.com/maximo" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <DOMAINID>KUBSKIPRSN</DOMAINID>
        <VALUE>SKIP ALL</VALUE>
        <DESCRIPTION>Skip All</DESCRIPTION>
        <ALNDOMAINID>3802</ALNDOMAINID>
        <VALUEID>KUBSKIPRSN|SKIP ALL</VALUEID>
    </ALNDOMAIN>
</ALNDOMAINMboSet>

What I had read previously about this was that you had to add the namespace to your xsl. In this case, I believe the namespace is the same namespace as my origianl XML document. So, I guessed that no other references were necessary.??

With that assumption, I ran the XSL below and it does not pull back any information related to the REST request.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:mea="http://www.ibm.com/maximo" exclude-result-prefixes="mea"
    version="1.0">
    <xsl:output method="xml" cdata-section-elements="" />

    <xsl:template match="/">
      <yyy:createJob xmlns:yyy="http://place.org/mmm/app">
        <job>
          <id />
          <origin>AMS</origin>
          <metaId>
            <xsl:value-of select="descendant::mea:WORKORDERID" />
          </metaId>
          <title>
            <xsl:value-of select="descendant::mea:DESCRIPTION" />
          </title>
          <dispatchGroup>FWSAMS</dispatchGroup>
          <priority>
            <xsl:value-of select="descendant::mea:WOPRIORITY" />
          </priority>
          <assignedTo>
            <xsl:value-of 
                select="descendant::mea:ASSIGNMENT/mea:LABORCODE" />
          </assignedTo>
          <jobDocument>
            <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
              <root>
                <workorderNum>
                  <xsl:value-of select="descendant::mea:WONUM" />
                </workorderNum>
                <xsl:apply-templates mode="copy"
                      select="descendant::mea:KUBROUNDENTRY" />
                <skipReasonDomain>
                  <xsl:variable name="myDomain">
                    <xsl:text>SKIPRSN</xsl:text>
                  </xsl:variable>
                  <xsl:value-of 
 select="document(concat('http://server.loc.org/maxrest/rest/mbo/alndomain/?
 domainid=',$myDomain))/descendant::VALUE"/>
                </skipReasonDomain>
              </root>
              <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
            </jobDocument>
            <completionDocument />
          </job>
        </yyy:createJob>
      </xsl:template>

    <xsl:template match="*" mode="copy">
    <xsl:element name="{local-name()}">
        <xsl:apply-templates select="node()" mode="copy" />
    </xsl:element>
    </xsl:template>

    <xsl:template match="text()|comment()" mode="copy">
      <xsl:copy/>
    </xsl:template>

</xsl:stylesheet>

This is the resulting XML document:

<yyy:createJob
xmlns:yyy="http://place.org/mmm/app">
<job>
    <id></id>
    <origin>AMS</origin>
    <metaId>2255202</metaId>
    <title>My Workorder Description</title>
    <dispatchGroup>FWSAMS</dispatchGroup>
    <priority>3</priority>
    <assignedTo>006325</assignedTo>
    <jobDocument>
        <![CDATA[<root><workorderNum>MWO-522</workorderNum><KUBROUNDENTRY><KUBROUNDENTRYID>267433</KUBROUNDENTRYID><LINEID>254735</LINEID><OBSERVATION/><KUBROUNDLINE><ASSETNUM>385691</ASSETNUM><METERNAME>VLOPSTAT</METERNAME><SEQUENCE>90</SEQUENCE><ASSET><ASSETID>388391</ASSETID><DESCRIPTION>Asset Description</DESCRIPTION><SERVICEADDRESS><STREETADDRESS>1234 Kingston Pike</STREETADDRESS></SERVICEADDRESS></ASSET><METER><DOMAINID>VLOPSTAT</DOMAINID><METERNAME>VLOPSTAT</METERNAME></METER></KUBROUNDLINE></KUBROUNDENTRY><KUBROUNDENTRY><KUBROUNDENTRYID>267432</KUBROUNDENTRYID><LINEID>254734</LINEID><OBSERVATION/><KUBROUNDLINE><ASSETNUM>385691</ASSETNUM><METERNAME>GLEAKGRD</METERNAME><SEQUENCE>80</SEQUENCE><ASSET><ASSETID>388391</ASSETID><DESCRIPTION>Asset2 Description</DESCRIPTION><SERVICEADDRESS><STREETADDRESS>2345 Kingston Pike</STREETADDRESS></SERVICEADDRESS></ASSET><METER><DOMAINID>CASEGRDE</DOMAINID><METERNAME>GLEAKGRD</METERNAME></METER></KUBROUNDLINE></KUBROUNDENTRY><skipReasonDomain/></root>]]>
    </jobDocument>
    <completionDocument></completionDocument>
</job>
</yyy:createJob>

My desired output would be:

<yyy:createJob
xmlns:yyy="http://place.org/mmm/app">
<job>
    <id></id>
    <origin>AMS</origin>
    <metaId>2255202</metaId>
    <title>My Workorder Description</title>
    <dispatchGroup>FWSAMS</dispatchGroup>
    <priority>3</priority>
    <assignedTo>006325</assignedTo>
    <jobDocument>
        <![CDATA[<root><workorderNum>MWO-522</workorderNum><KUBROUNDENTRY><KUBROUNDENTRYID>267433</KUBROUNDENTRYID><LINEID>254735</LINEID><OBSERVATION/><KUBROUNDLINE><ASSETNUM>385691</ASSETNUM><METERNAME>VLOPSTAT</METERNAME><SEQUENCE>90</SEQUENCE><ASSET><ASSETID>388391</ASSETID><DESCRIPTION>Asset Description</DESCRIPTION><SERVICEADDRESS><STREETADDRESS>1234 Kingston Pike</STREETADDRESS></SERVICEADDRESS></ASSET><METER><DOMAINID>VLOPSTAT</DOMAINID><METERNAME>VLOPSTAT</METERNAME></METER></KUBROUNDLINE></KUBROUNDENTRY><KUBROUNDENTRY><KUBROUNDENTRYID>267432</KUBROUNDENTRYID><LINEID>254734</LINEID><OBSERVATION/><KUBROUNDLINE><ASSETNUM>385691</ASSETNUM><METERNAME>GLEAKGRD</METERNAME><SEQUENCE>80</SEQUENCE><ASSET><ASSETID>388391</ASSETID><DESCRIPTION>Asset2 Description</DESCRIPTION><SERVICEADDRESS><STREETADDRESS>2345 Kingston Pike</STREETADDRESS></SERVICEADDRESS></ASSET><METER><DOMAINID>CASEGRDE</DOMAINID><METERNAME>GLEAKGRD</METERNAME></METER></KUBROUNDLINE></KUBROUNDENTRY><skipReasonDomain><VALUE>TRAFFIC</VALUE><VALUE>NOT FOUND</VALUE><VALUE>SKIP ALL</VALUE></root>]]>
    </jobDocument>
    <completionDocument></completionDocument>
</job>
</yyy:createJob>

I know this is a lot of information, but I hope it helps someone to understand what I am trying to do and how I might be able to get there. Any information is much appreciated.



لینک منبع

Use XML with HTML?


I`ve followed this link on youtube to make a small html page that can read XML file (link here: https://www.youtube.com/watch?v=WhKRbo8MANA)

I`ve done exactly the same as this guy, but the error message i get is:

“Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help, check https://xhr.spec.whatwg.org/”

What is wrong?

Here is my code:

<!DOCTYPE html>
<html xmlns = "http://www.w3.org/1999/xhtml">
    <body>
    <div>
    <script>
        if(window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.open("GET", "GetPredefinedTravelTimeLocations.xml", false);
        xmlhttp.send();
        xmlDoc = xmlhttp.responseXML;

        document.write("<table border='1'>");
        var x = xmlDoc.getElementByTagName("location");
        for ( i = 0; i < x.length; i++) {
            document.write("<tr><td>");
            document.write(x[i].getElementsByTagName("values")[0].childNodes[0].nodeValue);
            document.write("<tr><td>");
            document.write(x[i].getElementsByTagName("coordinates")[0].childNodes[0].nodeValue);
            document.write("<tr><td>");
        }
        document.write("</table>");
        </script></div>

    </body>
</html>

Somebody could help? thank you!



لینک منبع

c# – CryptoStream error when reading from xml files: System.Security.Cryptography.CryptographicException: ‘Bad Data. ‘


I am encrypting my data before saving it into the XML file but I am being given the following error when trying to read (load()) from files :

System.Security.Cryptography.CryptographicException: ‘Bad Data.’

The data is written (save()) correctly and is encypted.

The following is the save() method:

 protected void Save(string typeName)
    {
        string targetDirectory = CreateTargetDirectory(typeName);
        byte[] key = { 1, 2, 3, 4, 5, 6, 7, 8 }; 

        byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 };

        string filePath = targetDirectory + ID + ".xml";

        BinaryFormatter bformatter = new BinaryFormatter();
        DESCryptoServiceProvider des = new DESCryptoServiceProvider();

        using (var fs= new FileStream(filePath, FileMode.Create, FileAccess.Write))
        using (var cryptoStream = new CryptoStream(fs, des.CreateEncryptor(key, iv), CryptoStreamMode.Write))
        {

            bformatter.Serialize(cryptoStream, this);
            cryptoStream.Close();
        }
}

The following is the save() method:

protected static List<T> Load<T>(string typeName) where T:Person
    {
        byte[] key = { 1, 2, 3, 4, 5, 6, 7, 8 }; // Where to store these keys is the tricky part, 
                                                 // you may need to obfuscate them or get the user to input a password each time
        byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 };
        //۱٫ Create the result as an empty list
        List<T> result = new List<T>();

        //۲٫ Create the target directory
        string targetDirectory = CreateTargetDirectory(typeName);

        //۳٫ Find all the XML files in the target directory
        string[] xmlFilePaths = Directory.GetFiles(targetDirectory, "*.xml");

        //۴٫ Load each file and deserialize it
        //XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
        BinaryFormatter bformatter = new BinaryFormatter();
        //added code start >>>
        DESCryptoServiceProvider des = new DESCryptoServiceProvider();
        //added code end <<<<<

        foreach (string xmlFilePath in xmlFilePaths)
        {
            //using (FileStream dataStream = new FileStream(xmlFilePath, FileMode.Open))
            //Encryption
            using (var fs = new FileStream(xmlFilePath, FileMode.Open, FileAccess.Read))
            using (var cryptoStream = new CryptoStream(fs, des.CreateDecryptor(key, iv), CryptoStreamMode.Read))
            {
                //T person = (T)xmlSerializer.Deserialize(dataStream);
                //T person = (T)bformatter.Deserialize(dataStream);

                //result.Add(person);
                //added code start >>>>>>
                T person  = (T)bformatter.Deserialize(cryptoStream);
                //added code end <<<<<<
                result.Add(person);
            }
        }

        //۵٫ Return the result
        return result;
    }

Can anyone help please, as I am new in C Sharp. The error is being pointed to the line of code at the end of the load method, which is:

T person  = (T)bformatter.Deserialize(cryptoStream);



لینک منبع

xsd – Correct usage of xs:alternative in XML 1.1


This is how I’m defining an element with alternative types.

alternative.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
  elementFormDefault="qualified"
  vc:minVersion="1.1">

    <xs:complexType name="DefaultType">
        <xs:sequence>
            <xs:element name="string" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="OtherType">
        <xs:sequence>
            <xs:element name="number" type="xs:integer"/>
        </xs:sequence>
    </xs:complexType>

    <xs:element name="root">
        <xs:alternative test="@switchTo = 'OtherType'" type="OtherType"/>
        <xs:alternative type = "DefaultType"/>
    </xs:element>

</xs:schema>

sampleA.xml

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

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="alternative.xsd">

    <string>
        Sample
    </string>

</root>

sampleB.xml

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

<root switchTo="OtherType"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="alternative.xsd">

    <number>
        ۲۳۵۷۱۱۱۳
    </number>

</root>

First none of my validators supported it, so I switched to Oxygen XML for evaluation. It validates everything, and type resolution and validation works for every alternative, but I’m getting an error:

Attribute ‘switchTo’ is not allowed to appear in element ‘apply’.

I know the attribute is not defined for element ‘root’, but I also don’t know where I should define it! I’ve tried various places in an exploring manner, with no luck. Thank you for your time.



لینک منبع

Java: Get response from Solr in XML format


I am a newbie to Solr. I want to use Java to connect to my solr core and get the results back in XML format. By referring the official document, I am able to get the results in binary form. Below is my code:

public static void main(String[] args) throws SolrServerException, IOException {


        String urlString = "http://localhost:8983/solr/index1/";
        SolrClient solr = new HttpSolrClient.Builder(urlString).build();


        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");


        QueryResponse response = solr.query(query);
        System.out.println(response.toString());
    }

I also tried to research on how to get response. I found this link which says “If you want to get the raw xml response, just pick up any java HTTP Client, build the request and send it to Solr. You’ll get a nice XML String..” solr response in xml format
I coded the below code, but it is not giving me response

public static void main(String[] args) throws ClientProtocolException, IOException
{
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet("http://localhost:8983/solr/index1/select?q=*:*&wt=xml");
    CloseableHttpResponse response1 = httpclient.execute(httpGet);

    System.out.println(response1);
}

}

Output:

HttpResponseProxy{HTTP/1.1 200 OK [Content-Type: application/xml; charset=UTF-8, Transfer-Encoding: chunked] ResponseEntityProxy{[Content-Type: application/xml; charset=UTF-8,Chunked: true]}}

On the official site https://lucene.apache.org/solr/guide/6_6/using-solrj.html, it is mentioned to use

solr.setParser(new XMLResponseParser());

to get XML response, but I am not sure how to use it since any example is not given. Any help is appreciated.



لینک منبع

python – Append SubElement to existing XML using lxml


I am trying to append a Sub element to my existing Xml file using lxml.

XML File

<policyList>
        <policySecurity>
                <policyName>AutoAdd</policyName>
                <deviceName>PA-722</deviceName>
                <status>ACTIVE</status>
                <srcZone>any</srcZone>
                <dstZone>any</dstZone>
                <sourceAddr>5.5.5.5</sourceAddr>
                <destinationAddr>5.5.5.4</destinationAddr>
                <srcUser>any</srcUser>
                <application>any</application>
                <service>htds</service>
                <urlCategory>any</urlCategory>
                <action>deny</action>
        </policySecurity>
</policyList>

When trying to append the new element I first take user input through CLI and then match the element values with their corresponding text values and if it matches, I have to append the parameter not present.
The user sends the input like this ./pythonScript.cgi --sourceip 5.5.5.5 --destinationip 5.5.5.4 --service ssh
When this input is passed, since the service does not match, my code should append the service, by either adding another service tag or some other way.

pythonScript.cgi

gtree = etree.parse('../db/db_policy.xml')
    groot = gtree.getroot()
    for child in groot:
            dev = child.find('.//sourceAddr')
            if(dev.text == src_addr):
                    dev2 = dev.getparent()
                    newsub = etree.SubElement(dev, "service").text = ser
                    with open('XMLFile.xml', 'wb') as f:
                            f.write(etree.tostring(root, pretty_print = True))

but instead of appending the sub-element, it gives me the following traceback call:

Traceback (most recent call last):
  File "./ps_configset.cgi", line 162, in <module>
    f.write(etree.tostring(root, pretty_print = True))  
  File "src/lxml/etree.pyx", line 3367, in lxml.etree.tostring (src/lxml/etree.c:82622)

How can I achieve the required goal? Since this isn’t working for me, and it also deletes all the content that is there in my XML File.
Thanks in advance 🙂



لینک منبع

xml – ASP Classic – Folder proteced from public access, but accessible by script


I have a folder where I need save XML files that can’t be accessible publicly

root/xml_files/

But I need to access this folder with a ASP classic script to only read the files.

You guys have some tip how can I do this? What kind mechanism I can use to make this work?

Accepting any suggestions: coding, IIS permissions, etc.

A person suggested set a basic permission over this folder and than create a script to authenticate e read the files. But the scripts are to much complex…



لینک منبع

python – Two tree on group tag xml in odoo


i have a problem when i was write two tree in one group tag. this is my code :

<group>
    <field name='values_data' attrs="{'invisible': [('cover_data', '=', False)]}" nolabel='1'>
        <tree editable="bottom" create="1" class='scroll'>
            <field readonly_force_submit="1" readonly="True" name='no'/>
            <field readonly_force_submit="1" invisible="True"  name='stock'/>
            <field readonly_force_submit="1" readonly="True"  name='date2'/>
            <field readonly_force_submit="1" name='ref'/>
            <field readonly_force_submit="1" name='tax'/>
            <field readonly_force_submit="1" name='date_ta'/>
            <field readonly_force_submit="1" name='calc'/>
            <field readonly_force_submit="1" readonly="True"  name='calc2'/>
        </tree>
    </field>

    <field name='values_data_false' attrs="{'invisible': [('cover_data', '=', True)]}" nolabel='1'>
        <tree editable="bottom" create="1" class='scroll'>
            <field readonly_force_submit="1" readonly="True" name='no'/>
            <field readonly_force_submit="1" invisible="True"  name='stock'/>
            <field readonly_force_submit="1" readonly="True"  name='date2'/>
            <!-- <field readonly_force_submit="1" name='ref' invisible='1'/> -->
            <field readonly_force_submit="1" name='tax' invisible='1'/>
            <!-- <field readonly_force_submit="1" name='date_ta' invisible='1'/> -->
            <field readonly_force_submit="1" name='calc' invisible='1'/>
            <field readonly_force_submit="1" readonly="True"  name='calc2'/>
        </tree>
    </field>
</group>

In file .py, i was give a condition for values_data which mean for choose the tree, but what i got, the system always process the both of tree. My expectation if the values_data variable True of False, the process just take or process one tree, not both of tree.



لینک منبع

Quickbooks Process Request error = 80042500, There was an error when parsing the provided XML file


Looking at the XML Validator tool I get the following response from trying to import my qbpos xml query into Quickbooks Enterprise.

Requested validation for QB POS (qbposxml), file has processing instruction indicating
Reason: The element ‘QBPOSXML’ is used but not declared in the DTD/Schema.
Here is the start to the xml file, can anyone shine some light into what the problem is here? Using qbposfc3 for the AppendPurchaseOrderQueryRq() to create the xml response in C#.

<?xml version="1.0" encoding="windows-1252"?>
<QBPOSXML>
  <QBPOSXMLMsgsRs>
    <PurchaseOrderQueryRs requestID="0" retCount="18" statusCode="0" statusMessage="Status OK" statusSeverity="Info">
      <PurchaseOrderRet>



لینک منبع

Create a XML Decoder from a string or byte array GO


I have a xml decode function in my app and I use xml.NewDecoder(resp.Body) to decode my xml. the NewDecoder functions receives an io.Reader. But the problem is that in my response from the server I receive the first 230 bytes i need to ignore and the remaining bytes are the xml encoded in base64 that I want to decode. Here an example of the response body:

    --RandomCaracteres...
    Content-Type: application/xml; charset=UTF-8; name=response_xml

    <Response success="1"/>
    --RandomCaracteres...
    Content-Type: text/xml; name=report.xml
    Content-Transfer-Encoding: base64
    PE5leHBvc2VSZXBvcnQgdmVyc2lvbj0iMi4wIj4KPHNjYW5zPgo8c2NhbiBpZD0iNDYwMCIgbmFt......

I need to read only the PE5leHBvc2VSZXBv… data. With the following code I can read the xml:

    bodyBytes, _ := ioutil.ReadAll(resp.Body)
    defer resp.Body.Close()
    data, err := base64.StdEncoding.DecodeString(string(bodyBytes)[230:])
    fmt.Println(data)

but I can’t call the xml.NewDecoder() function because data is not a io.Reader type. Is there any way to creade a Decode object from a string?



لینک منبع