Solved

XML newbie question - how to structure my files

Posted on 2014-02-06
8
245 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:Alexandre Takacs
[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:Alexandre Takacs
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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:Alexandre Takacs
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:Alexandre Takacs
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

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!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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