Solved

XML newbie question - how to structure my files

Posted on 2014-02-06
8
243 Views
Last Modified: 2014-02-06
Hello

I am starting a new project in which I have a create and the read XML files in VB.net

I am pretty much free to structure my files in which ever way I see fit. On the reading side I have to use the MSXML libraries / parser.

My file would tentatively have the following structure

Item1
Property1
Property2

Item2
Property1
Property2

etc

As such I have come up with
<?xml version="1.0" encoding="UTF-8"?>

<item>
	<itemnum>1</itemnum>	
	<property>
    my property value
    </property>
</item>

<item>
	<itemnum>2</itemnum>	
	<property>
    some other property value
    </property>
</item>

Open in new window


which will not parse correctly.

I'm sure this is an obvious newbie question but how should I structure my files ?
0
Comment
Question by:atak2983
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 500 total points
ID: 39838784
you will need to wrap item elements in one root element
<items> would be a good idea

like this

<items>
    <item>
        <itemnum>1</itemnum>
        <property> my property value </property>
    </item>

    <item>
        <itemnum>2</itemnum>
        <property> some other property value </property>
    </item>
</items>

Open in new window

0
 
LVL 1

Author Comment

by:atak2983
ID: 39838790
aha - gotcha - so you always need a "root" node and after that you can go about your merry way :) ?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39838805
From the processing point of view actually there is a general tendency to group similar elements in a container

<?xml version="1.0" encoding="UTF-8"?>
<items>
    <item>
        <itemnum>1</itemnum>
        <properties>
            <property> my property value </property>
            <property> my property value 2 </property>
        </properties>
    </item>

    <item>
        <itemnum>2</itemnum>
        <properties>
            <property> some other property value </property>
            <property> some other property value 2</property>
        </properties>
    </item>
</items>

Open in new window


it makes the processing easier
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39838806
correct, an XML document can only have one root element
0
 
LVL 1

Author Comment

by:atak2983
ID: 39838817
Thanks - things are starting to take shape...

I have another issue with the generated code where (I guess) the online editor I am using a playing some tricks on me. Say I have

<property> this is a test... </property>

it translates into

<property> this is a test &hellip; </property>

which will create a parsing error.

Again pretty sure these are minor and obvious gotchas but wondering how to avoid them...
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 39838829
yes that is an 'online' issue
&hellip; is a character entity (consider it a macro) which is allowed in an XML document if you also declare it in the document.
HTML works the same way, but there the entities are hard coded in the browser
so "&hellip;" makes sense to a browser in a HTML file, it only makes sense in an XML if you tell the XML what it is
The safest around it is to replace the hellip with the numeric character entity
"&#133;"
0
 
LVL 1

Author Closing Comment

by:atak2983
ID: 39838834
Ok thanks - I think my most immediate questions have been answered :)
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39838847
welcome... and good luck
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with error in Query 2 39
VB.NET String Settings and Temp Folder Question 3 69
TSQL XML Namespaces 7 35
Filtering a datagrid view 8 34
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question