<?xml version="1.0" encoding="UTF-8"?>
<manifest identifier="D2L_1000000179" xmlns:d2l_2p0="http://desire2learn.com/xsd/d2lcp_v2p0" xmlns="http://www.imsglobal.org/xsd/imscp_v1p1">
<resources>
<resource identifier="res_question_library" type="webcontent" d2l_2p0:material_type="d2lquestionlibrary" d2l_2p0:link_target="" href="questiondb.xml" title="Question Library" />
<resource identifier="res_quiz_1000000179" type="webcontent" d2l_2p0:material_type="d2lquiz" d2l_2p0:link_target="" href="quiz_d2l_1000000179.xml" title="Quiz to test D2L import" />
</resources>
</manifest>
I want to create this xml file .
but when i am creating this using Xelement or XmlElemenmt i am getting this one
<?xml version="1.0" encoding="UTF-8"?>
<manifest identifier="D2L_1000000179" xmlns:d2l_2p0="http://desire2learn.com/xsd/d2lcp_v2p0" xmlns="http://www.imsglobal.org/xsd/imscp_v1p1">
<resources>
<resource identifier="res_question_library" type="webcontent" material_type="d2lquestionlibrary" link_target="" href="questiondb.xml" title="Question Library" />
<resource identifier="res_quiz_1000000179" type="webcontent" material_type="d2lquiz" link_target="" href="quiz_d2l_1000000179.xml" title="Quiz to test D2L import" />
</resources>
</manifest>
here d2l_2p0:material_type is coming like material_type.
some one help me to create this using .net framework.
code for this is here below
private void createMenifetData(string destPath, long listExam)
{
XmlDocument xDoc = new XmlDocument();
XmlDeclaration xmlDeclaration = xDoc.CreateXmlDeclaration("1.0", "UTF-8", "");
XmlElement rootnode = xDoc.CreateElement("manifest");
xDoc.InsertBefore(xmlDeclaration, xDoc.DocumentElement);
rootnode.SetAttribute("identifier", "D2L_" + listExam.ToString());
rootnode.SetAttribute("xmlns:d2l_2p0", "http://desire2learn.com/xsd/d2lcp_v2p0");
rootnode.SetAttribute("xmlns", "http://www.imsglobal.org/xsd/imscp_v1p1");
XmlElement resources = xDoc.CreateElement("resources");
XmlElement resource = xDoc.CreateElement("resource");
resource.SetAttribute("identifier", "res_question_library");
resource.SetAttribute("type", "webcontent");
resource.SetAttribute(#"d2l_2p0:material_type", "d2lquestionlibrary");
resource.SetAttribute(#"d2l_2p0:link_target", "");
resource.SetAttribute("href", "questiondb.xml");
resource.SetAttribute("title", "Question Library");
resources.AppendChild(resource);
XmlElement resource1 = xDoc.CreateElement("resource");
resource1.SetAttribute("identifier", "res_quiz_" + listExam);
resource1.SetAttribute("type", "webcontent");
resource1.SetAttribute(#"d2l_2p0:material_type", "d2lquiz");
resource1.SetAttribute(#"d2l_2p0:link_target", "");
resource1.SetAttribute("href", "quiz_d2l_" + listExam + ".xml");
resource1.SetAttribute("title", "Quiz to test D2L import");
resources.AppendChild(resource1);
rootnode.AppendChild(resources);
xDoc.AppendChild(rootnode);
xDoc.Save(destPath + "\\imsmanifest.xml");}
XNamespace defaultNamespace = "http://www.imsglobal.org/xsd/imscp_v1p1";
const string NAMESPACE_URI = "http://desire2learn.com/xsd/d2lcp_v2p0";
const string NAMESPACE_PREFIX = "d2l_2p0";
XNamespace otherNamespace = NAMESPACE_URI;
XElement root = new XElement(defaultNamespace + "manifest",
new XAttribute("identifier", "D2L_1000000179"),
new XAttribute(XNamespace.Xmlns + NAMESPACE_PREFIX, NAMESPACE_URI),
new XElement(defaultNamespace + "resources",
new XElement(defaultNamespace + "resource",
new XAttribute("identifier", "res_question_library"),
new XAttribute("type", "webcontent"),
new XAttribute(otherNamespace + "material_type", "d2lquestionlibrary"),
new XAttribute(otherNamespace + "link_target", ""),
new XAttribute("href", "questiondb.xml"),
new XAttribute("title", "Question Library")),
new XElement(defaultNamespace + "resource",
new XAttribute("identifier", "res_quiz_1000000179"),
new XAttribute("type", "webcontent"),
new XAttribute(otherNamespace + "material_type", "d2lquiz"),
new XAttribute(otherNamespace + "link_target", ""),
new XAttribute("href", "quiz_d2l_1000000179.xml"),
new XAttribute("title", "Quiz to test D2L import"))));
Since you tagged this VB I'd just go the simplest route and use XML literals:
Dim T = <manifest identifier="D2L_1000000179" xmlns:d2l_2p0="http://desire2learn.com/xsd/d2lcp_v2p0" xmlns="http://www.imsglobal.org/xsd/imscp_v1p1">
<resources>
<resource identifier="res_question_library" type="webcontent" d2l_2p0:material_type="d2lquestionlibrary" d2l_2p0:link_target="" href="questiondb.xml" title="Question Library"/>
<resource identifier="res_quiz_1000000179" type="webcontent" d2l_2p0:material_type="d2lquiz" d2l_2p0:link_target="" href="quiz_d2l_1000000179.xml" title="Quiz to test D2L import"/>
</resources>
</manifest>
This kicks out:
<manifest identifier="D2L_1000000179" xmlns:d2l_2p0="http://desire2learn.com/xsd/d2lcp_v2p0" xmlns="http://www.imsglobal.org/xsd/imscp_v1p1">
<resources>
<resource identifier="res_question_library" type="webcontent" d2l_2p0:material_type="d2lquestionlibrary" d2l_2p0:link_target="" href="questiondb.xml" title="Question Library" />
<resource identifier="res_quiz_1000000179" type="webcontent" d2l_2p0:material_type="d2lquiz" d2l_2p0:link_target="" href="quiz_d2l_1000000179.xml" title="Quiz to test D2L import" />
</resources>
</manifest>
Use CreateAttribute method on XMLDocument to create an attribute with a namespace. Later append to the attributes collection of xmlelement that should have this attribute.
public XmlAttribute CreateAttribute(
string qualifiedName,
string namespaceURI
)
Related
I am trying to update a xml on basis of id.
my xml file looks like this
<?xml version="1.0" standalone="yes"?>
<CATALOG>
<CD>
<ID>0</ID>
<HeaderDetailID>0</HeaderDetailID>
<FirstName>
</FirstName>
<LastName>
</LastName>
<EmployeeID>
</EmployeeID>
<Department>
</Department>
<Postion>
</Postion>
<Application>
</Application>
<Filter>
</Filter>
<AreaorCountryorStation>
</AreaorCountryorStation>
<NetworkDomain>
</NetworkDomain>
<Action>
</Action>
<NameOfController>
</NameOfController>
<Status>
</Status>
</CD>
<CD>
<ID>1</ID>
<HeaderDetailID>1</HeaderDetailID>
<FirstName>Basant</FirstName>
<LastName>Basant</LastName>
<EmployeeID>Basant</EmployeeID>
<Department>Basant</Department>
<Postion>Basant</Postion>
<Application>
</Application>
<Filter>
</Filter>
<AreaorCountryorStation>Basant</AreaorCountryorStation>
<NetworkDomain>Basant</NetworkDomain>
<Action>
</Action>
<NameOfController>Basant</NameOfController>
<Status>Request Completed</Status>
</CD>
</CATALOG>
Now I try to fetch id from hidden field and get It on server side to update the node name status.
for (int i = 0; i < DateData.Length - 1; i++)
{
string iRecordID = DateData[i];
XmlDocument xmlDoc = new XmlDocument();
string filepathsUpdate = Server.MapPath("Contact.xml");
xmlDoc.Load(filepathsUpdate);
XmlNode node = xmlDoc.SelectSingleNode("/CATALOG/CD[ID=" + DateData[i] + "]/Status");
node.InnerText = "Request Completed";
xmlDoc.Save(filepathsUpdate);
}
It works locally fine but on server it doesn't work.
Can I close the connection in XML file
I feel like xmlDoc.Save not working
This is the command i'm running:
E:\Invoice\maindoc>xsd.exe /c CurrencyCode.xsd LanguageCode.xsd MIMEMediaTypeCode.xsd UnitCode.xsd UBL-CommonAggregat eComponents-2.0.xsd UBL-CommonBasicComponents-2.0.xsd UnqualifiedDataTypeSchemaModule-2.0.xsd UBL-CommonExtensionComponents-2.0.xsd UBL-QualifiedDatatypes-2.0.xsd UBL-Invoice-2.0.xsd
I generated CS class. this is part of the test source code
var invoice = new InvoiceType();
invoice.IssueDate = new IssueDateType();
invoice.IssueDate.Value = DateTime.Now;
var supplier = new SupplierPartyType();
supplier.CustomerAssignedAccountID = new CustomerAssignedAccountIDType();
supplier.CustomerAssignedAccountID.Value = "5461564646";
supplier.AdditionalAccountID = new AdditionalAccountIDType[1];
supplier.AdditionalAccountID[0] = new AdditionalAccountIDType
{
Value = "6"
};
supplier.Party = new PartyType();
supplier.Party.PartyName = new PartyNameType[1];
supplier.Party.PartyName[0] = new PartyNameType
{
Name = new NameType1 { Value = "EMPRESA X" }
};
invoice.AccountingSupplierParty = supplier;
string fichero = #"E:\InvoiceXsd\pruebas.xml";
XmlSerializer serializer = new XmlSerializer(typeof(InvoiceType));
FileStream fs = new FileStream(fichero, FileMode.Create);
serializer.Serialize(fs, invoice);
fs.Close();
The part of "pruebas.xml" generated is this:
<?xml version="1.0"?>
<Invoice
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<ID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">F001-10</ID>
<IssueDate xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2016-04-22</IssueDate>
<InvoiceTypeCode xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">01</InvoiceTypeCode>
<AccountingSupplierParty xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
<CustomerAssignedAccountID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">20272874680</CustomerAssignedAccountID>
<AdditionalAccountID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">6</AdditionalAccountID>
<Party>
<PartyName>
<Name xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">nombre empresa</Name>
</PartyName>
<PostalAddress>
<ID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">150114</ID>
<StreetName xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">DIRECCION</StreetName>
<CitySubdivisionName xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" />
<CityName xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">DEPARTAMENTO</CityName>
<CountrySubentity xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">DISTRITO</CountrySubentity>
<District xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">LUGAR</District>
<Country>
<IdentificationCode xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">ES</IdentificationCode>
</Country>
</PostalAddress>
<PartyLegalEntity>
<RegistrationName xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">NOMBRE EMPRESA</RegistrationName>
</PartyLegalEntity>
</Party>
</AccountingSupplierParty>
In the element "Invoice" do not have the imports tha was generated from xsd.exe command. In the all elements is without the namespace xsd.
The result should be like this. :
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><Invoice
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2"
xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<cac:AccountingSupplierParty>
<cbc:CustomerAssignedAccountID>20100454523</cbc:CustomerAssignedAccountID>
<cbc:AdditionalAccountID>6</cbc:AdditionalAccountID>
<cac:Party>
<cac:PostalAddress>
<cbc:ID>150111</cbc:ID>
<cbc:StreetName>AV. LOS PRECURSORES #1245</cbc:StreetName>
<cbc:CitySubdivisionName>URB. MIGUEL GRAU</cbc:CitySubdivisionName>
<cbc:CityName>LIMA</cbc:CityName>
<cbc:CountrySubentity>LIMA</cbc:CountrySubentity>
<cbc:District>EL AGUSTINO</cbc:District>
<cac:Country>
<cbc:IdentificationCode>PE</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyLegalEntity>
<cbc:RegistrationName>SOPORTE TECNOLOGICOS EIRL</cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingSupplierParty>
What am I doing wrong? Any help would be greatly appreciated.
how to i do to get the cbc, cac, ... namespace preceders in the nodes?
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
...
serializer.Serialize(fs, invoice, ns);
i write some application on MVC and i need to make that stuff which i write
i need to get xml response like this:
<?xml version="1.0" encoding="utf-8"?>
<getAllShepherdsResponse xmlns="http://www.sheeps.pl/webapi/1_0">
<shepherds>
<shepherd>
<errors>
<error code="1">error1</error>
<error code="-2147483647">error2</error>
<error code="2147483647">error3</error>
</errors>
<shepherdId>1</shepherdId>
<name>name1</name>
<sheeps>
<sheep>
<id>1</id>
<colour>colour1</colour>
<createdOn>1900-01-01T01:01:01+01:00</createdOn>
</sheep>
<sheep>
<id>-2147483647</id>
<colour>colour2</colour>
<createdOn>0001-01-01T00:00:00+01:00</createdOn>
</sheep>
</sheeps>
</shepherd>
</shepherds>
</getAllShepherdsResponse>
i create this code, it easy to look
which create XDocument with Xelements from database
and for the first Xelement i had addin namespace but its wants to work propertly, what is my problem?:
protected XNamespace xn = "http://www.sheeps.pl/webapi/1_0";
XDocument(new XDeclaration("1.0", "utf-8", "yes"),
new XElement(xn+"getAllShepherdsResponse",
from emp in db.Shepherds.ToList()
select new XElement("shepherd",
new XElement("shepherdId", emp.Id),
new XElement("name", emp.Name),
new XElement("sheeps", from sp in emp.Sheep
select new
XElement("sheep", new XElement("id", sp.Id), new XElement("colour", sp.Colour),new XElement("createdOn", sp.CreatedOn))))));
and i get that why i get so "xmlns" near shepherd?:
<getAllShepherdsResponse xmlns="http://www.sheeps.pl/webapi/1_0">
<shepherd xmlns="">
<shepherdId>1</shepherdId>
<name>A</name>
<sheeps>
<sheep>
<id>1</id>
<colour>Red</colour>
<createdOn />
</sheep>
<sheep>
<id>2</id>
<colour>Blue</colour>
<createdOn />
</sheep>
</sheeps>
</shepherd>
</getAllShepherdsResponse>
You need to create all elements in the namespace, as with
new XElement(xn+"getAllShepherdsResponse",
from emp in db.Shepherds.ToList()
select new XElement(xn+"shepherd",
new XElement(xn+"shepherdId", emp.Id),
new XElement(xn+"name", emp.Name),
new XElement(xn+"sheeps", from sp in emp.Sheep
select new
XElement(xn+"sheep", new XElement(xn+"id", sp.Id), new XElement(xn+"colour", sp.Colour),new XElement(xn+"createdOn", sp.CreatedOn))))));
I write code like this
XmlDocument xdocMulticom = new XmlDocument();
StringWriter strwMultiXml = new StringWriter();
XmlTextWriter xmlMultiAirInfo = new XmlTextWriter(strwMultiXml);
xmlMultiAirInfo.Formatting = Formatting.None;
xmlMultiAirInfo.WriteStartDocument();
xmlMultiAirInfo.WriteStartElement("ns", "cancelreservation", "http://www.opentravel.org/ota/2003/05");
xmlMultiAirInfo.WriteStartElement("OTA_VehCancelRQ");
xmlMultiAirInfo.WriteAttributeString("xmlns", "http://www.opentravel.org/ota/2003/05");
xmlMultiAirInfo.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
xmlMultiAirInfo.WriteAttributeString("Version", "1.002");
xmlMultiAirInfo.WriteAttributeString("PrimaryLangID", "EN");
xmlMultiAirInfo.WriteAttributeString("ReqRespVersion", "2.001");
xmlMultiAirInfo.WriteStartElement("POS");
xmlMultiAirInfo.WriteStartElement("Source");
xmlMultiAirInfo.WriteStartElement("RequestorID");
xmlMultiAirInfo.WriteAttributeString("Type", "4");
xmlMultiAirInfo.WriteAttributeString("ID", "F0F4CCE4A9C24355");
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteStartElement("VehCancelRQCore");
xmlMultiAirInfo.WriteAttributeString("CancelType", "Cancel");
xmlMultiAirInfo.WriteStartElement("UniqueID");
xmlMultiAirInfo.WriteAttributeString("Type", "14");
xmlMultiAirInfo.WriteAttributeString("ID", "N2169641");
xmlMultiAirInfo.WriteStartElement("PersonName");
xmlMultiAirInfo.WriteElementString("GivenName", "Sandra");
xmlMultiAirInfo.WriteElementString("Surname", "Jhonsan");
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteStartElement("VehCancelRQInfo");
xmlMultiAirInfo.WriteStartElement("Vendor");
xmlMultiAirInfo.WriteAttributeString("Code", "ZR");
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xdocMulticom.LoadXml(strwMultiXml.ToString());
which generates output like this:
<?xml version="1.0" encoding="utf-16"?>
<ns:cancelreservation xmlns:ns="http://www.opentravel.org/ota/2003/05">
<OTA_VehCancelRQ xmlns="http://www.opentravel.org/ota/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.002" PrimaryLangID="EN" ReqRespVersion="2.001">
<POS>
<Source>
<RequestorID Type="4" ID="F0F4CCE4A9C24355" />
</Source>
</POS>
<VehCancelRQCore CancelType="Cancel">
<UniqueID Type="14" ID="N2169641">
<PersonName>
<GivenName>Sandra</GivenName>
<Surname>Jhonsan</Surname>
</PersonName>
</UniqueID>
</VehCancelRQCore>
<VehCancelRQInfo>
<Vendor Code="ZR" />
</VehCancelRQInfo>
</OTA_VehCancelRQ>
</ns:cancelreservation>
Which is ok to me but i need it to be like this:
<?xml version="1.0" encoding="utf-16"?>
<ns:cancelreservation>
<OTA_VehCancelRQ xmlns="http://www.opentravel.org/ota/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.002" PrimaryLangID="EN" ReqRespVersion="2.001">
<POS>
<Source>
<RequestorID Type="4" ID="F0F4CCE4A9C24355" />
</Source>
</POS>
<VehCancelRQCore CancelType="Cancel">
<UniqueID Type="14" ID="N2169641">
<PersonName>
<GivenName>Sandra</GivenName>
<Surname>Jhonsan</Surname>
</PersonName>
</UniqueID>
</VehCancelRQCore>
<VehCancelRQInfo>
<Vendor Code="ZR" />
</VehCancelRQInfo>
</OTA_VehCancelRQ>
</ns:cancelreservation>
Is there any way to change it?
As I See, difference only in namespace in first node... (or it's my mistake?)
Replace this line:
xmlMultiAirInfo.WriteStartElement("ns", "cancelreservation", "http://www.opentravel.org/ota/2003/05");
with this.
xmlMultiAirInfo.WriteStartElement("ns", "cancelreservation", "");
Well, C# is doing all right. Because your element doesn't know about such prefix.
In your sample, "cancelreservation" is not the root element, but if it will be root, xmlns attribute must be present.
I'm stuck with some task here. I want to write to xml file.
Here is the file:
<?xml version="1.0" encoding="utf-8"?>
<lists>
<plannedList>
<Skift-a></Skift-a>
<Skift-b></Skift-b>
<Skift-c></Skift-c>
<Skift-d></Skift-d>
<Skift-e></Skift-e>
</plannedList>
<requestedList>
<Skift-a></Skift-a>
<Skift-b></Skift-b>
<Skift-c></Skift-c>
<Skift-d></Skift-d>
<Skift-e></Skift-e>
</requestedList>
</lists>
then i want to use c# and for example dataset or an other method to add a jobID under the loggedIn Skift. so if Skift-a is logged on, and press a button, i want the xml file to look like this:
<?xml version="1.0" encoding="utf-8"?>
<lists>
<plannedList>
<Skift-a></Skift-a>
<Skift-b></Skift-b>
<Skift-c></Skift-c>
<Skift-d></Skift-d>
<Skift-e></Skift-e>
</plannedList>
<requestedList>
<Skift-a></Skift-a>
<jobID>1<jobID/>
<Skift-b></Skift-b>
<Skift-c></Skift-c>
<Skift-d></Skift-d>
<Skift-e></Skift-e>
</requestedList>
</lists>
And here is what I've tried so far:
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(this.Page.Server.MapPath("~/StoredData/JobsByUsers.xml"));
XmlNode Skift = xmldoc.SelectSingleNode("/requestedList/" + User.Identity.Name.ToString());
XmlNode newJobID = xmldoc.CreateNode(XmlNodeType.Element, "jobID", null);
newJobID.InnerText = topID.ToString();
Skift.AppendChild(newJobID);
xmldoc.Save(this.Page.Server.MapPath("~/StoredData/JobsByUsers.xml"));