Click here to Skip to main content
15,920,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

I would like to create an xml file with the following structure

XML
<?xml version="1.0"?>
<Category>Mobile Phones
  <Subcategory>Samsung Phones
  <Brand>Samsung
    <Product>
      <title>SAMSUNG B7722I WHITE DUALSIM SAMSUNG B7722I WHITE DUALSIM
      </title>
      <Network>GSM 850 / 900 / 1800 / 1900 - SIM 1 </Network>
  <Dimensions>113.5 x 55.5 x 14.3 mm Greutate : 112 g Weight: 112 g  </Dimensions>
    <Camera>5 MP, 2560x1920 pixels, LED flash </Camera>
    <Radio>Stereo FM radio with RDS, FM recording </Radio><Standby>Up to 420 h </Standby>
    <TalkTime>Up to 12 h 50 min</TalkTime>
    </Product>
    <Product>
      <title>
        SAMSUNG GALAXY S WIFI 4.0 WHITE
      </title>
      <Network>N / A  </Network>
      <Weight> </Weight>
      <Camera>3.15 MP, 2048x1536 pixels, autofocus, LED flash  </Camera>
      <Radio>Stereo FM radio with RDS  </Radio>

    </Product>
  </Brand>

  </Subcategory>
  <Subcategory>
    NOKIA Phones

    <Brand>
     Nokia
      <Product>
        <title>
          NOKIA N8 PINK
        </title>
        <Network>GSM 850 / 900 / 1800 / 1900  </Network>
        <Dimensions>113.5 x 59.1 x 12.9 mm, 86 cc </Dimensions>
        <Camera>5 MP, 2560x1920 pixels, LED flash </Camera>
        <Standby>Up to 420 h </Standby>
        <TalkTime>Up to 12 h 50 min</TalkTime>
        <weight>135 g</weight>
        <Rooms>12 MP, 4000x3000 pixels, Carl Zeiss optics, autofocus, Xenon flash </Rooms>
        <Radio>Stereo FM radio with RDS, FM transmitter </Radio>
      </Product> </Brand>
  </Subcategory>
</Category>




I would like to show the xml file like the following link with a specific condition like subcategory= nokia phone or samsung phone

http://translate.google.com/translate?hl=en&sl=ro&tl=en&u=http%3A%2F%2Fwww.quickmobile.ro%2Ftelefoane-nokia[^]

How its possible
pls help


Thank you,
soumya
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jun-11 14:26pm    
Is the XML schema (meta-data) already pre-defined or you can modify it? What you show is not a schema but just one sample. I'm asking because there is much better approach. What if you leave the data structure the same but change the form of XML?
--SA

I would also suggest XSLT as a way of rendering XML conditionally, and converting it to be more human readable. You don't say, but I assume you don't want to show raw XML ?
 
Share this answer
 
Comments
Wonde Tadesse 6-Jun-11 7:27am    
Good suggestion. 5+
As Kim said LINQ to XML[^] is good. But if you want to work with OO way, then XML Serialization[^] is way to go.

I hope this helps you well.
 
Share this answer
 
You can use LINQ to XML[^] to create/modify and delete elements in XML.

With LINQ to XML you can easy create XML like this:
C#
XElement xmlTree1 = new XElement("Root",
    new XElement("Child1", 1),
    new XElement("Child2", 2),
    new XElement("Child3", 3),
    new XElement("Child4", 4),
    new XElement("Child5", 5),
    new XElement("Child6", 6)
);


And output is:

XML
<Root>
  <Child3>3</Child3>
  <Child4>4</Child4>
  <Child5>5</Child5>
</Root>


Hope it can help you.
 
Share this answer
 
v2
Comments
Wonde Tadesse 5-Jun-11 16:37pm    
5+
Kim Togo 6-Jun-11 2:47am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900