Solved

XML newbie question - how to structure my files

Posted on 2014-02-06
8
238 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
  • 5
  • 3
8 Comments
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
correct, an XML document can only have one root element
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:atak2983
Comment Utility
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
Comment Utility
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
Comment Utility
Ok thanks - I think my most immediate questions have been answered :)
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
welcome... and good luck
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WPF issue with Trigger 2 65
GridDataView 6 44
Convert Oracle data into XML document 2 37
System32Int Error 8 44
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now