Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XML newbie question - how to structure my files

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

Assisted Solution

by:Geert Bormans
Geert Bormans earned 2000 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
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: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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

971 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