Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Small XML Question.

Featured Replies

was wondering if i could have some advice. I am creating a basic XML that represents a file that i have made for a project. I have developed an application, its basic, its a form that has different attributes on it, which can be filled out and submitted. Once submitted, it creates SVG Shapes. I am now looking into making a basic XML file to display the different fields involved.

 

I have been reading on W3Schools about XML etc and i have started to make my XML code for my file. I have attached the code that i have done. I was just wondering if i could get some advice to see that i am going about it the correct way. As you can see there are shapes and within the shapes there are different attributes. The one thing that confuses me is that different shapes have different attributes eg a square does not have a radius. How does this affect my XML file? From examples i have seen each one has the same attributes included e.g a CD Collection Name, Year Released etc. But my shapes depending on which one they are all different?#. Is what i have attached correct or do you guys have any advice on what i could do to change it.

 

What i have so far:-

 

<shape>

<shapetype>Circle</shapetype>

<xaxis>50</xaxis>

<yaxis>50</yaxis>

<radius>70</radius>

</shape>

 

<shape>

<shapetype>Rectangle</shapetype>

<xaxis>50</xaxis>

<yaxis>50</yaxis>

<width>70</width>

<height>70</height>

</shape>

 

Thanks in advance!

Not really sure what the question is but here is a long winded answer... Firstly, they are not attributes, they are child nodes (or child elements). An attribute is meta-data within the tag, e.g

 

<shape type="rectangle">
   <height>70</height>
</shape>

 

The shape node's 'type' attribute is 'rectangle' and the nodes height is 70. You can nest elements as well, for example

 

<shape type="rectangle">
   <dimensions>
       <height>70</height>
       <width>20</width>
   </dimensions>
</shape>

 

This is a better way of defining your shapes as it is better formed and more readable, particularly if your file is really big and your text editor supports XML element collapsing, it can aid human readability. Also it can make it easier to query your data using xpath (in my opinion).

 

You don't need to worry about putting in elements that do not appear in adjacent elements, like the radius element you mentioned. Its your XML file so you can put whatever data you want in it, and it doesn't matter if different elements appear in some nodes and not in other. However if you wish to validate your XML file and specify which elements and attributes can appear and which can't, you can make a DTD (Document Type Definition) in which XML readers can validate the XML file against. More details on DTD can be found on W3Schools - http://www.w3schools.com/dtd/default.asp

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.