Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Beginner question

Status
Not open for further replies.

Keetso

Technical User
Nov 18, 2003
49
0
0
CA
Hi. I'm new to XML and will be taking a formal XML class next month and have been doing some pre-emptive studying using the (working) code below. I was hoping you'd be able to clarify something for me:

The first line is the version/character set declaration.
The second line is a "comment" line, I believe. (noting the "!" after the ">" symbol)

My question involves the next line, beginning with "<ProvisioningRequest......".

Since the last line is "</ProvisioningRequest>, shouldn't this be considered the Root Element? If so, then why would "ProductType", "TransactionID", etc be included where it is? Shouldn't the ">" bracket be placed directly after the the line as such: <ProvisioningRequest>, and then have the "ProductType", "TranasactionID", etc info follow this instead of the way it's written below, the ">" bracket (that would correspond with "<ProvisioningRequest....") is after the, Version="1.1"> line.

Could anyone explain this to me or point me in the right direction for the answer?

If I've made no sense what so ever, please don't hesitate to ask for clarification.

TIA!

K

------------------------------

<?xmlversion="1.0" encoding="UTF-8"?>
<!DOCTYPE ProvisioningRequest SYSTEM "ProvisioningRequest.dtd">
<ProvisioningRequest
ProductType="Widget"
TransactionId="CCBS:CAY:test5:169.18.3.255:7200:987654321"
TransactionType="Suspend"
Version="1.1">
<Header>
<Sender id="000012345" name="ABC Company">
<Login>testadmin</Login>
<Password>password</Password>
</Sender>
<TimeStamp>2004-03-26T01:07:57</TimeStamp>
</Header>
<Body>
<ProvisioningEntity name="subscriber">
<ProvisioningDataItem name="MSISDN">
13451234567
</ProvisioningDataItem>
<ProvisioningDataItem name="IMSI">
346140102123456
</ProvisioningDataItem>
</ProvisioningEntity>
</Body>
</ProvisioningRequest>

 
An xml-node can have attributes as well as child-nodes.
<node1 attr1="1" attr2="two">
<childnode1 attr3="3"/>
<childnode2 attr4="four">Hello</childnode2>
</node1>
Though one could argue that an attribute is just a child-node in a different notation, there is an important difference: the value of an attribute is not part of the content of a node.
Therefore one reason to use attributes instead of subnodes, is that you can be sure they will not accidently show up in the result of an xsl-transformation.
 
But since these are declared within the Root element (node), they are then attributed for each instance of a child element? For example, using the example above, if there're 2 "Body" elements instead of 1 with the following values:

</Header>
<Body>
<ProvisioningEntity name="subscriberONE">
<ProvisioningDataItem name="MSISDN">
13451234567
</ProvisioningDataItem>
<ProvisioningDataItem name="IMSI">
346140102123456
</ProvisioningDataItem>
</ProvisioningEntity>
</Body>
</Header>
<Body>
<ProvisioningEntity name="subscriberTWO">
<ProvisioningDataItem name="MSISDN">
24562345678
</ProvisioningDataItem>
<ProvisioningDataItem name="IMSI">
457251213234567
</ProvisioningDataItem>
</ProvisioningEntity>
</Body>

would each "Body" element ("SubscriberONE", "SubscriberTWO")also have the Root element values "ProductType="Widget", "TransactionType="Suspend", etc as well?

Thanks again for the response. It's starting to make sense and that's scaring me!

K
 
Attributes belong only to one node, not to child-nodes or parent-nodes. So:
would each "Body" element ("SubscriberONE", "SubscriberTWO")also have the Root element values "ProductType="Widget", "TransactionType="Suspend", etc as well?
In a way yes, they share the same parentnode that has these attributes.
In a transformation you might need to find the ProductType that 'sort of applies to' a Body-node, and you would reference: "give me the ProductType-attribute of the parentnode", which would return the same attribute in both cases. There's a query-language called x-path to do things like that.
 
Oh and by the way:
The second line is a "comment" line, I believe. (noting the "!" after the ">" symbol)
No, a 'comment' would be <!-- text -->

<!DOCTYPE ProvisioningRequest SYSTEM "ProvisioningRequest.dtd">
is a reference to a document-type-definition, a file where the structure of the xml is described.
 
Humm, the <!DOCTYPE ..> is not required to point to
an external file. The following is perfectly
valid.

Code:
<?xml version = "1.0"?>

<!DOCTYPE format [
   <!ELEMENT p ( #PCDATA | s )* >
   <!ELEMENT s ( #PCDATA ) >
]>

<p>
A
<s>B</s>
C
<s>D</s>
E
</p>

Finally, as the XML recommendation states "it is possible to construct a well-formed document containing a doctypedecl that neither points to an external subset nor contains an internal subset."

 
Thanks to all for the education. I appreciate it.

Hopefully you all won't mind if I should have further questions once I disseminate what you've already told me.

Thanks again.

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top