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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Root elements how to?

Status
Not open for further replies.

evaleah

Programmer
Mar 18, 2003
252
US
Hi all. I am looking at using XML for data transfer for the first time and have already stumbled on needing multiple root elements.

My dataset needs to have the following elements:
<PUB>
<AL>
<A>Ackloo, S</A>
<A>Terlouw, JK</A>
<A>Ruttink, PJ</A>
<A>Burgers, PC</A>
</AL>
<T>Analysis of carrageenans by matrix-assisted laser desorption/ionization and electrospray ionization mass spectrometry. I. kappa-Carrageenans</T>
<J>Rapid Commun Mass Spectrom</J>
<Y>2001</Y>
<V>15</V>
<P>1152-9</P>
</PUB>

The issue is that I need to have multiple authors for the same publication. Can anyone give me an idea of how to approach this?

Thank you so much!
Eva
 
You can't have multiple root elements, as that would violate the W3C standards.

I would do something like this:
Code:
<?xml encoding=&quot;UTF-8&quot; version=&quot;1.0&quot;?>
<Publications>
  <Publication>
    <Authors>
      <Author>Adam Able</Author>
      <Author>Betty Baker</Author>
      <Author>Charlie Chucky</Author>
    </Authors>
    <Title>Ship Captain: The Captain Hazelwood story</Title>
    <Year>200</Year>
    <Price currency=&quot;USD&quot;>35.98</Price>
  </Publication>
  <Publication>
    <Authors>
      <Author>Dave Delta</Author>
      <Author>Echo Early</Author>
      <Author>Frank Foxtrot</Author>
    </Authors>
    <Title>Have Beret, Will Travel: Monica's story</Title>
    <Year>200</Year>
    <Price currency=&quot;USD&quot;>35.98</Price>
  </Publication>
  <Publication>
    <Authors>
      <Author>William Gates</Author>
    </Authors>
    <Title>Money: Why I have it and you don't</Title>
    <Year>200</Year>
    <Price currency=&quot;USD&quot;>35.98</Price>
  </Publication>
</Publications>

Chip H.



If you want to get the best response to a question, please check out FAQ222-2244 first
 
Thanks for the advice. However, this is essentially what I have. I just shortened the headers to single letters.

Let me be much more specific about my problem..... I am using ASP.Net to import this XML file. When I execute a DataSetName.ReadXML I get an error that there are multiple root elements.

I stripped the XML file down to having only one author:
<PUB>
<A>Burgers, PC</A>
<T>Analysis of carrageenans</T>
<J>Rapid Commun Mass Spectrom</J>
<Y>2001</Y>
<V>15</V>
<P>1152-9</P>
</PUB>

and it works beautifully. I am assuming there is another approach to this so that I can import everything using the ReadXML method of the dataset object. Or, do I need to keep formatting it the way I am formatting it and just import it a different way?

Is there another way to approach this than including the authors in a sublist?

Thanks,
Eva
 
Let me update this....

I have managed to get the file imported into a dataset using the original formatting I had. The problem was in the XML file there were some errors, not the basic structure itself. But the authors are not coming through at all.

All the other information is coming through nicely. Any other ideas???

Thanks
 
I would look at a possible encoding problem. If you leave the encoding off on the XML file, it defaults to UTF-8. But if you're inserting into regular fields (CHAR, VARCHAR) and not Unicode fields (NCHAR, NVARCHAR) you could have a problem.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top