Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Digby 23 posts 43 karma points
    Oct 26, 2009 @ 20:13
    Digby
    0

    V4 GetXmlDocumentByUrl fails when reading web service with xmlns data

    I have created a simple web service that sends an arraylist of a data structure.

    I can get this using GetXmlDocumentByUrl but cannot iterate through the collection. If I remove the generated xmlns statements manually everything works OK.. I have scanned the net and unable to find a simple way to remove these statements in the web service.

    Thanks for your help

    Sample Xml Document

    <?xml version="1.0" encoding="utf-8"?>
    <ArrayOfInstitutionListInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
    <InstitutionListInfo>
    <Id>1</Id>
    <Abbreviation>Direct</Abbreviation>
    <Fullname>Engineering Council</Fullname>
    <FeaniCode>999</FeaniCode>
    <Standing>1</Standing>
    </InstitutionListInfo>
    <InstitutionListInfo>
    <Id>2</Id>
    <Abbreviation>IOA</Abbreviation>
    <Fullname>Institute of Acoustics</Fullname>
    <FeaniCode>ACO</FeaniCode>
    <Standing>1</Standing>
    </InstitutionListInfo>
    </ArrayOfInstitutionListInfo>

    XSLT

    <xsl:variable name="xml" select="umbraco.library:GetXmlDocumentByUrl(concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'),
    '/xml dump/test.xml'))"/>

    <xsl:template match="/">
    <ul>
    <xsl:for-each select="$xml/ArrayOfInstitutionListInfo/InstitutionListInfo">
    <li><xsl:value-of select="Abbreviation" />test</li>
    </xsl:for-each>
    </ul>
    </xsl:template>

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Oct 26, 2009 @ 21:59
    Chriztian Steinmeier
    1

    Hi there,

    All you need is a little knowledge of namespaces - because of the last xmlns attribute in the XML you're transforming, the elements of the file exists in the http://tempuri.org-namespace, so you'll need to map the namespace-uri "http://tempuri.org/" to a prefix in your XSLT file and use that prefix on the elements you're selecting:

    Add the namespace to the <xsl:stylesheet> instruction:

    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umbraco.library="urn:umbraco.library"
        xmlns:tmp="http://tempuri.org/"
    >

    and then prefix the elements you're selecting:

     

     <xsl:for-each select="$xml/tmp:ArrayOfInstitutionListInfo/tmp:InstitutionListInfo">
              <li><xsl:value-of select="tmp:Abbreviation" />test</li>
        </xsl:for-each>

    /Chriztian

     

  • Digby 23 posts 43 karma points
    Oct 27, 2009 @ 09:33
    Digby
    0

    Well many thanks Chriztian, this all works fine now. Your prompt reply has really helped me out.. Hope I can return the favour some time

    Digby

     

Please Sign in or register to post replies

Write your reply to:

Draft