dimanche 8 novembre 2015

xsd substitution or xlt transformation

How Do I Change this XSD using substitution to get the following outcome?


I have a XML that is being returned from my asp.net api from a Saas providor. The service comes from asp.net mvc however, I can only use asp classic, and i'm pretty limited in what i can do. I can send TSQL queries to the sql server 2005... Other than that theres not much that can be done. So my only option for what i need (well my best current option) is this. The data returns from my asp classic page service.asp. service.asp returns the structured xml based off an XSD file that is in the same folder as my script to get the data. I'll show you what it currently returns, what the current xsd is, and what it should return, and the modifications I tried making to the XSD. Hopefully that's the info someone will need to help me as this isn't exactly my strong suite. Thanks!

Current XML Response

Currently the data returns like this:

<xmldata>
    <group>
        <groupid>1</groupid>
        <parentid>2</parentid>
        <item>133</item>
        <ProductCode>blahblah</ProductCode>
        <ProductName>blahblah</ProductName>
    </group>
    <group>
        <groupid>2</groupid>
        <parentid>2</parentid>
        <item>134</item>
        <ProductCode>blahblah</ProductCode>
        <ProductName>blahblah</ProductName>
    </group>
    <group>
        <groupid>2</groupid>
        <parentid>2</parentid>
        <item>313</item>
        <ProductCode>blahblah</ProductCode>
        <ProductName>blahblah</ProductName>
    </group>
    <group>
        <groupid>3</groupid>
        <parentid>2</parentid>
        <item>46</item>
        <ProductCode>blahblah</ProductCode>
        <ProductName>blahblah</ProductName>
    </group>
</xmldata>

Current XSD File

My current XSD File is structured as follows:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="xmldata" xmlns="" xmlns:xs="http://ift.tt/tphNwY" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
  <xs:element name="xmldata" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="groups">
          <xs:complexType>
            <xs:sequence>
              <xs:element msprop:TableNameXsd="groupid" name="groupid" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
              <xs:element name="ParentID" msprop:SqlDbType="Int" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="groupproductlink">
          <xs:complexType>
            <xs:sequence>
              <xs:element msprop:TableNameXsd="groupproductlink" name="ID" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
              <xs:element name="groupID" msprop:SqlDbType="Int" minOccurs="0" />
              <xs:element name="ProductCode" msprop:SqlDbType="Int" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="Products">
          <xs:complexType>
            <xs:sequence>
              <xs:element msprop:TableNameXsd="Products" name="AutoDropShip" msprop:maxLength="1" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" msprop:SQLFrom="FROM vm.Products p INNER JOIN vm.Products_Descriptions pd ON p.ProductCode = pd.ProductCode INNER JOIN vm.PE pe ON p.ProductCode = pe.ProductCode INNER JOIN vm.Products_Memos pm ON p.ProductCode = pm.ProductCode" minOccurs="0" />
              <xs:element name="productid" msprop:maxLength="30" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="1" />
              <xs:element name="ProductCode" msprop:SQLTableAlias="p" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
              <xs:element name="ProductName" msprop:maxLength="255" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>


What the XML Should Be

The XML Needs to be returned in the following way (please note the attribute becoming the element)

<groups>
    **<1> //<---Element=groupID**
        <item>133</item>
        <parentid>2</parentid>
        <ProductCode>blahblah</ProductCode>
        <ProductName>blahblah</ProductName>
    **</1> //<---Element=groupID
    <2> //<---Element=groupID**
        <item>134</item>
        <parentid>2</parentid>
        <ProductCode>blahblah</ProductCode>
        <ProductName>blahblah</ProductName>
    **</2> //<---Element=groupID
    <2> //<---Element=groupID**
        <item>313</item>
        <parentid>2</parentid>
        <ProductCode>blahblah</ProductCode>
        <ProductName>blahblah</ProductName>e="1">
    **</2> //<---Element=groupID
    <3> //<---Element=groupID**
        <item>46</item>
        <parentid>2</parentid>
        <ProductCode>blahblah</ProductCode>
        <ProductName>blahblah</ProductName>
    **</3> //<---Element=groupID**
</groups>


The XSD I attempted to use and didn't get any response

I tried transforming the XSD that I listed above to the following:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="groups" xmlns="" xmlns:xs="http://ift.tt/tphNwY" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
  **<xs:element name="groups" *msdata:IsDataSet="true"* msdata:UseCurrentLocale="true">**
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="groupid" *msdata:IsDataSet="true"* msdata:UseCurrentLocale="true" msprop:TableNameXsd="groupid" msprop:SqlDbType="Int" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element msprop:TableNameXsd="groupid" name="groupid" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
              <xs:element name="ParentID" msprop:SqlDbType="Int" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="groupproductlink">
          <xs:complexType>
            <xs:sequence>
              <xs:element msprop:TableNameXsd="groupproductlink" name="ID" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
              <xs:element name="groupID" msprop:SqlDbType="Int" minOccurs="0" />
              <xs:element name="ProductCode" msprop:SqlDbType="Int" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="Products">
          <xs:complexType>
            <xs:sequence>
              <xs:element msprop:TableNameXsd="Products" name="AutoDropShip" msprop:maxLength="1" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" msprop:SQLFrom="FROM vm.Products p INNER JOIN vm.Products_Descriptions pd ON p.ProductCode = pd.ProductCode INNER JOIN vm.PE pe ON p.ProductCode = pe.ProductCode INNER JOIN vm.Products_Memos pm ON p.ProductCode = pm.ProductCode" minOccurs="0" />
              <xs:element name="productid" msprop:maxLength="30" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="1" />
              <xs:element name="ProductCode" msprop:SQLTableAlias="p" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
              <xs:element name="ProductName" msprop:maxLength="255" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>


However, It doesn't work currently. I think maybe I need to use a substitution group, however unfortunately it's been years since I did this and I can't remember what exactly I need to do. I truly hope someone here has some better ideas!

Thanks for your assistance. If you have any questions let me know and I'll do my best to answer them!

Aucun commentaire:

Enregistrer un commentaire