Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
[Re-posted XML checking for duplicates before saving, if duplicate found tell me about it — SA]


Hello again,

what im trying to achive is to read part of my XML and put that node into a weblink.

I.E

www.Helloworld.com/[APIKEY]/[VCODE].jpg

as you can see i've got an ID so when i want to do multiples.

My XML looks like this.
XML
  </L><?xml version="1.0" encoding="utf-8"?>
<L xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ID>1c890a19-deae-406b-9e3f-5aeb779d06d4</ID>
  <APIKEY>123</APIKEY>
  <VCODE>123</VCODE>
</L><?xml version="1.0" encoding="utf-8"?>
<L xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ID>d179e9de-ec45-4986-9081-48ebb7466e46</ID>
  <APIKEY>1234</APIKEY>
  <VCODE>1234</VCODE>
</L><?xml version="1.0" encoding="utf-8"?>
<L xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ID>a169216d-efba-4bc2-86a8-1ba8fee3e585</ID>
  <APIKEY>12345</APIKEY>
  <VCODE>12345</VCODE>
</L> 


Here is how i made my XML.
C#
public class L
   {
       static void main(string[] args)
       {
           XmlDocument xmldoc = new XmlDocument();
           xmldoc.Load("data.XML");
           XmlNodeList userNodes = xmldoc.SelectNodes("data.XML");
           foreach (XmlNode userNode in userNodes) ;

       }

       private string id;
       private string APIkey;
       private string VCode;

       public string ID
       {
           get { return id; }
           set { id = Guid.NewGuid().ToString(); }
       }

       public string APIKEY
       {
           get { return APIkey; }
           set { APIkey = value; }
       }

       public string VCODE
       {
           get { return VCode; }
           set { VCode = value; }

       }

       public static void SaveData(object obj, string Filename)
       {

           XmlSerializer sr = new XmlSerializer(obj.GetType());
           TextWriter writer = new StreamWriter(Filename, true);
           sr.Serialize(writer, obj);
           writer.Close();

       }


Im trying to import a picture here using the link + the info in my XML.
C#
private void pictureBox1_Click(object sender, EventArgs e)
      {
          pictureBox1.ImageLocation = "www.Helloworld.com /[line in XML] /[the other line].jpg";

      }


Thanks in advance :)
Posted
Updated 28-Aug-15 6:30am
v3
Comments
Afzaal Ahmad Zeeshan 28-Aug-15 11:51am    
You can use the string.Format(); to format the URL. You need to work with System.Xml namespace also. These will give you the answer.
DamithSL 28-Aug-15 11:52am    
what have you tried so far?
Member 11841936 28-Aug-15 11:58am    
so far I've tried google... this is my first project and my skills are poor.
Sergey Alexandrovich Kryukov 28-Aug-15 12:09pm    
Tried Google... Are you serious?
—SA
Sergey Alexandrovich Kryukov 28-Aug-15 12:09pm    
Try what? Look thoroughly: this is not XML at all. Please see Solution 1.
—SA

1 solution

You cannot do it, because you data file is not an XML file. Try to open it any browser; it will tell you why. XML should have one root element. Have a correct XML file, first of all, well-formed, and it will work.

[EDIT]
Alternatively, create your own proprietary standard, call it, say, "SuperXML" (especially if it is going to be a superset of XML) and create your own generator, parser, and perhaps serialization. It is quite possible. Only avoid the name "XML" and better even the file naming schema *.XML.
[END EDIT]

But wait a minute… People already explained you this problem: XML checking for duplicates before saving, if duplicate found tell me about it[^].

Why would you ignore those comments? And remember, re-posting is considered as abuse. Main part here is: if you cannot use advice which you already got, who would like to waste time on your re-posted questions? There is a little hope now that you will use the.

—SA
 
Share this answer
 
v4
Comments
Member 11841936 28-Aug-15 12:14pm    
SA, this is a different question ... it was mentioned that my XML is wrong and to add a root and then work from that, however I didn't know then it would not work with what I'm trying to do now. I'm sure reposting the same question is "abuse".

Now that you have politely pointed it out to me, I will now go back and re-do my XML.
Sergey Alexandrovich Kryukov 28-Aug-15 12:32pm    
It is not "different enough". Not only the same question, but posting so similar question is abuse, but main abuse is ignoring the advice. You could use "Improve question" and add more comments on the page of your previous question; it would be perfectly correct way to conduct.

It's good that you are going to re-do the XML. Will you accept the answer formally then?

Thank you for understanding.

—SA

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