Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am quite new to WPF and I am trying to use an XML file for binding a TreeView in the XAML file. Using some of your posts I managed to visualize a basic xml file, now I have a problem to export my xls file to xml.

My xls file consists in 3 columns: id, name, surname. Actually, I have 2 rows (this is an example), they are:
- 100 Mary Smith
- 200 Clara White

I'd like to export that as an XML, just like:
XML
<Root>
     <100> 
     <name> Mary </name>
     <surname> Smith </surname>
     </100>

     <200> 
     <name>Clara </name>
     <surname> White </surname>
     </200>
</Root>

I'd like to write down a XSD and using it for mapping the xls file, but I don't know how organize the schema to have that groups.
Can you help me with this example?

Thanks in advance

What I have tried:

I have tried with this XSD file, but I don't have the id value on the top of the nodes (it stays on the same level of name)

<pre><?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
  <element name="Root">
		 <complexType>
			<sequence>
				<element name="identity" maxOccurs="unbounded">
					<complexType>
						<sequence>
							<element name="ID" />
							<element name="NAME"/>
						</sequence>
					</complexType>
				</element>
			</sequence>
		</complexType>
  </element>
</schema>


Is it possible to bring the id value on the top of the Group? Just like:
ID
----NAME
----SURNAME
Posted
Updated 18-Oct-17 4:35am
Comments
RedDk 18-Oct-17 15:39pm    
Well, the mapping you've got currently is not based upon the .xls tabl to which you refer and, knowing MS Excel as well as I do, the notorius disconnect that exists between a standard "xml" and a MS flavor of "xml" is likely the culprit when it comes to anyone's misunderstanding going forward. Without getting too wordy then, let me just say that with a table that looks as yours does in the .xls you have ... do this:

1. Save-As "XML Spreadsheet 2003" .xml
2. Open that saved MS flavor of .xml with notepad
3. See the Line 39 <row> tag
4. THIS (following that <row> tag) IS the form of the table you want

Meaning if you copy and paste that <row> to <row> blurb into any <root></root> notepad .txt then saved IT as .xml, you'd get what that XLS table looks like in STANDARD XML. Fagettabout MS XML my friend!

Now ask more questions about what you have and what you want.

[edit]
... sorry, can't paste XML here ... so after an edit of that std xml you'll invariably see that you must make an ELEMENT out of an ATTRIBUTE ... as suggested somewhat by PO beneath here when he intimates numeric stuff will have to be converted to alphabetic stuff ...
[end sorry edit]

1 solution

According to w3schools[^], you cannot name a xml element with only digits.
Here are the rules:
Element names are case-sensitive
Element names must start with a letter or underscore
Element names cannot start with the letters xml (or XML, or Xml, etc)
Element names can contain letters, digits, hyphens, underscores, and periods
Element names cannot contain spaces

So, no, it is not possible to define a schema the way you presented it to us (because it would mean defining an element whose name is composed only of digits). Moreover, you seem to confound the name of the element (id) with its value (100, 200, etc.).
You would better create a record element (for example), having three elements in it: id, name, surname. You can also make these elements as attributes of the record element, since they all are simple integer and string values. But that's a matter of personal preference.
Hope this helps.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900