0
votes

I try to get a numbering on the contacts

I've got following :

---
 // remark other fields from the xml that are not from the contacts I left out to shorten this post on stackoverflow
 <ns0:contacts recordnr="0">
               <ns0:name/>
               <ns0:tel/>
               <ns0:gsm/>
               <ns0:fax/>
               <ns0:email/>
               <ns0:website/>
            </ns0:contacts>
            <ns0:contacts recordnr="1">
               <ns0:name/>
               <ns0:tel/>
               <ns0:gsm/>
               <ns0:fax/>
               <ns0:email/>
               <ns0:website/>
            </ns0:contacts>
            <ns0:contacts recordnr="2">
               <ns0:name/>
               <ns0:tel/>
               <ns0:gsm/>
               <ns0:fax/>
               <ns0:email/>
               <ns0:website/>
            </ns0:contacts>           
---

I would want to change it like this :

 // remark other fields from the xml that are not from the contacts I left out to shorten this post on stackoverflow
---
         <ns0:contacts>
               <ns0:name/>
               <ns0:tel/>
               <ns0:gsm/>
               <ns0:fax/>
               <ns0:email/>
               <ns0:website/>
            </ns0:contacts>
            <ns1:contacts>
               <ns1:name/>
               <ns1:tel/>
               <ns1:gsm/>
               <ns1:fax/>
               <ns1:email/>
               <ns1:website/>
            </ns1:contacts>
            <ns2:contacts>
               <ns2:name/>
               <ns2:tel/>
               <ns2:gsm/>
               <ns2:fax/>
               <ns2:email/>
               <ns2:website/>
            </ns2:contacts>
---

Or if not possible on each separated field, at least a different number on the contacts section, like for the 3th contact :

         <ns2:contacts>
               <ns0:name/>
               <ns0:tel/>
               <ns0:gsm/>
               <ns0:fax/>
               <ns0:email/>
               <ns0:website/>
            </ns2:contacts>

My XSD type for the Contacts looks like this :

   <xsd:complexType name="ContactsType">
        <xsd:sequence>
            <xsd:element name="name" maxOccurs="1" minOccurs="0"
                         type="xsd:string"/>
            <xsd:element name="tel" maxOccurs="1" minOccurs="0"
                         type="xsd:string"/>
            <xsd:element name="gsm" maxOccurs="1" minOccurs="0"
                         type="xsd:string"/>
            <xsd:element name="fax" maxOccurs="1" minOccurs="0"
                         type="xsd:string"/>
            <xsd:element name="email" maxOccurs="1" minOccurs="0"
                         type="xsd:string"/>
            <xsd:element name="website" maxOccurs="1" minOccurs="0"
                         type="xsd:string"/>
        </xsd:sequence>
        <xsd:attribute name="recordnr" type="int"/>
    </xsd:complexType>

My XSD type (adminstakeholder) that includes the XSD Contacts looks like this :

<xsd:complexType name="AdminStakeholderType">
        <xsd:sequence>
            <xsd:element name="ashId" maxOccurs="1" minOccurs="1"
                         type="xsd:long"/>
            <xsd:element name="isLegalPerson" type="xsd:boolean"
                         minOccurs="1" maxOccurs="1"/>
            <xsd:element name="naturalPerson" maxOccurs="1"
                         minOccurs="0" type="tns:NaturalPersonType"/>
            <xsd:element name="legalPerson" maxOccurs="1" minOccurs="0"
                         type="tns:LegalPersonType"/>
            <xsd:element name="category" maxOccurs="1" minOccurs="0"
                         type="tns:CategoryType"/>
            <xsd:element name="orafinNumber" maxOccurs="1" minOccurs="0"
                         type="xsd:string"/>
            <xsd:element name="address" maxOccurs="1" minOccurs="0"
                         type="tns:AddressType"/>
            <xsd:element name="contacts" maxOccurs="10"
                         minOccurs="0"
                         type="tns:ContactsType"/>
            <xsd:element name="synonyms" maxOccurs="1"
                         minOccurs="0" type="tns:SynonymsType"/>
            <xsd:element name="kbo" maxOccurs="1" minOccurs="0"
                         type="tns:KboType"/>
        </xsd:sequence>
    </xsd:complexType>

This schema is used : xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"

In the examples I left out the real data values, just showing the empty fields.

Basically what I need is the prefix "ns" is to be followed by a incrementing or unique number for each record of Contact. I order to get this, I created a attribute "recordnr" but that's not conform the business requirements. I do not want to see the recordnr attribute in the output XLK. I need the value from that recordnr following the prefix "ns" or, not using the recordnr but a autoincrementing number.

Anyone has a suggestion ?

All help appreciated

1
the prefix is a placeholder for the namespace defined elsewhere. if you want a prefix with a counter then you need to define for each Contact a new namespace. I think this is incorrect use of the namespace. the format that you currently have is the correct way. - martijn

1 Answers

1
votes

XSD can only deal with namespace-well formed XML, so prefixes like ns0:x and ns1:x can only be used if they are bound to namespaces.

It's in any case poor design practice to pack element and attributes names with instance-level meaning. Stick to the convention that element and attribute names are defined by the data model, whereas values (text nodes and attribute values) depend on the instance data. XML doesn't require that convention (you can represent someone's personal name as <Michael>Kay</Michael> if you really want), but life is much easier if you swim with the tide.