Question Help with XML Output

Simeon

Member
Joined
Sep 14, 2009
Messages
13
Programming Experience
Beginner
I have a Dataset, and must generate some XML. The XML used to output like this:

A)
VB.NET:
- <Clauses>
  <ClauseCode>TM004</ClauseCode> 
  <ClauseCode>TM005</ClauseCode> 
  <ClauseCode>TM012</ClauseCode> 
</Clauses>
</RiskDetails>

From my dataset it looks like
B)
VB.NET:
- <Clauses>
  <ClauseCode>TM004</ClauseCode> 
  </Clauses>
- <Clauses>
  <ClauseCode>TM005</ClauseCode> 
  </Clauses>
- <Clauses>
  <ClauseCode>TM012</ClauseCode> 
  </Clauses>
  </RiskDetails>


I've attached the design and what the relationship looks like.
What must I change to get it to look like (A) again?

Thanks
 

Attachments

  • Relation.jpg
    Relation.jpg
    20.7 KB · Views: 16
  • DatasetDiagram.jpg
    DatasetDiagram.jpg
    25.9 KB · Views: 14
Have you tried:
VB.NET:
Dim ds As New DataSet()
...
ds.WriteXml("yourXmlPath")
 
Clauses is the table and there will be opening and closing brackets for each record generated from the table such as your example b section. The only other thing that I can think of is changing it to output a the clausecode as an attribute of each clause record.
 
Thanks Tom. Could you explain that further?
The Employee section is coming out in the correct way:
VB.NET:
- <Employees>
  <NumberEmployed Category="111">1</NumberEmployed> 
  <NumberEmployed Category="006">2</NumberEmployed> 
  <NumberEmployed Category="119">3</NumberEmployed> 
  </Employees>

If I look at the XML, I see there is an attribute in the Employee section:

VB.NET:
                                <xs:element name="Employees" minOccurs="0" maxOccurs="unbounded">
                                  <xs:complexType>
                                    <xs:sequence>
                                      <xs:element name="NumberEmployed" minOccurs="0" maxOccurs="unbounded">
                                        <xs:complexType>
                                          <xs:simpleContent msdata:ColumnName="NumberEmployed_text" msdata:Ordinal="1">
                                            <xs:extension base="xs:long">
                                              <xs:attribute name="Category" type="xs:string" />
                                            </xs:extension>
                                          </xs:simpleContent>
                                        </xs:complexType>
                                      </xs:element>
                                    </xs:sequence>
                                  </xs:complexType>
                                </xs:element>


Where as the Clause Codes section is
VB.NET:
                          <xs:element name="Clauses" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element name="ClauseCode" type="xs:string" />
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>

From within the XSD, both datatables seem to be setup the same. How do I change the Clauses section to use attributes instead?

Thanks
 
Last edited:
NumberedEmployed is showing its own record the same as example b in your original post, because NumberedEmployed is the table name same as Clauses. The difference is of course your not seeing child nodes for each of the child record columns/fields because instead you are outputting them as attributes within each of the table records itself.

Trying to clarify, each table record will have start and end tags of the table name. For instance, Table1 may have 5 columns to output and two hundred records. Each of the two hundred records will start and end with Table1.

In your last posting, it only appears different but is really the same thing. The Parent table is Employees so you have opening and closing table record brackets for each Employees record and within that you have opening and closing table record brackets for each NumberedEmployees record too, your just not seeing child nodes, for each of the columns since you are instead having the values appear as attributes within the parent records.
 
Last edited:
As far as typed datasets within VB, I know .Net 2003 used to allow me to choose whether each column was an element or an attribute, I dont see the same options within VB 2008. I'd be interested if anyone knew the answer of how to convert the fields. I would think there would be an option within the designer if it was allowable but so far I dont see a way without going into the coding itself.
 
I can't find any option within the Dataset designer within VB 2005.
In the end, I edited the schema with Notepad! Then just added the changed schema to the project.
Hardly ideal, but it does seem the best way at the moment.
Btw, since the data is the same, would you think Clients would care which format they got it in? I have to add another table, and I think I'll won't use the attribute method this time.
 
Just having this conversation in another thread, no there doesnt seem to be an attribute property/option within the designer anymore although as you already figured out you can change it within the schema coding.

::shrugs:: who knows with clients/customers... Ive had some that would have whole board mettings asking them to change one country code. However the dataset.readxml works the same with both attributes & elements so there shouldnt be any large changes needed for reading the xml file.
 
Back
Top