|
28.04.2009., 21:18 | #1 |
Registered User
Datum registracije: Feb 2007
Lokacija: MOSTAR
Postovi: 16
|
.NET i XML problem
Ljudi dali mi netko može pomoći da mi se u dokument na kraj elementa ne dodaje xmlns="" Primjer: imam spreman XML file koji izgleda ovako: <?xml version="1.0" encoding="UTF-8"?> <PORUKA xmlns="http://www.xyz.net/epp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" PID="" Datum=""> </PORUKA> Kreiram novi XDocument iz te datoteke: xd = XDocument.Load("Poruka0.xml"); zatim unutar poruke dodajem novi element sa potrebnim atributima: _xd.Root.Add( new XElement("PAKET", new XAttribute("IDpaketa", ""), new XAttribute("br_naloga", ""), new XAttribute("suma", "")) ); i nakon toga mi dokument izgleda ovako: <?xml version="1.0" encoding="utf-8"?> <PORUKA xmlns="http://www.pincom.net/epp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" PID="23" Datum="2009-04-28T18:34:28"> <PAKET IDpaketa="128" br_naloga="28" suma="" xmlns="" /> </PORUKA> Ne znam XML pa mi ovo nije jasno, ali mi zbog ovoga xmlns="" dokument nije validan! Dali mi netko može pomoći? |
01.05.2009., 02:25 | #2 |
Premium
Datum registracije: Feb 2009
Lokacija: Pozega
Postovi: 93
|
CODE: --------- XDocument doc = new XDocument( new XElement("TrivadisLocations", new XElement("Location", new XAttribute("City","Basel"), new XElement("Consultants", new XElement("Consultant", new XAttribute("FirstName", "Thomas"), new XAttribute("LastName", "Huber") ), new XElement("Consultant", new XAttribute("FirstName", "Christoph"), new XAttribute("LastName", "Pletz") ) ) ), new XElement("Location", new XAttribute("City", "Freiburg"), new XElement("Consultants", new XElement("Consultant", new XAttribute("FirstName", "Thomas"), new XAttribute("LastName", "Wukasch") ) ) ), new XElement("Location", new XAttribute("City","Zürich"), new XElement("Consultants", new XElement("Consultant", new XAttribute("FirstName", "Patrick"), new XAttribute("LastName", "Spieler") ) ) ) ) ); doc.Save("locations.xml"); REZULTAT ----------- <?xml version="1.0" encoding="utf-8"?> <TrivadisLocations> <Location City="Basel"> <Consultants> <Consultant FirstName="Thomas" LastName="Huber" /> <Consultant FirstName="Christoph" LastName="Pletz" /> </Consultants> </Location> <Location City="Freiburg"> <Consultants> <Consultant FirstName="Thomas" LastName="Wukasch" /> </Consultants> </Location> <Location City="Zürich"> <Consultants> <Consultant FirstName="Patrick" LastName="Spieler" /> </Consultants> </Location> </TrivadisLocations> Zadnje izmijenjeno od: markaV. 01.05.2009. u 02:41. |
|
|
Oglas
|
|
|
|