Solved

XML newbie question - how to structure my files

Posted on 2014-02-06
8
239 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
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39838806
correct, an XML document can only have one root element
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 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