2

Here is the required XML format that I am looking for:

<mf:package 
 xmlns="urn:x-lexisnexis:content:manifest:global:1"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="urn:x-lexisnexis:content:manifest:global:1 sch_manifest.xsd"
 mf:mf="urn:x-lexisnexis:content:manifest:global:1">

What I am getting is:

<mf:package 
 xmlns="urn:x-lexisnexis:content:manifest:global:1"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="urn:x-lexisnexis:content:manifest:global:1 sch_manifest.xsd" 
 xmlns:mf="urn:x-lexisnexis:content:manifest:global:1">

The code I am using is:

using (XmlWriter writer = XmlWriter.Create(parentPathPackage + packageID + "_man.xml", settings))
{
    writer.WriteStartElement("mf", "package", "urn:x-lexisnexis:content:manifest:global:1");
    writer.WriteAttributeString("", "xmlns", null, "urn:x-lexisnexis:content:manifest:global:1");
    writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
    writer.WriteAttributeString("xsi", "schemaLocation", null, "urn:x-lexisnexis:content:manifest:global:1 sch_manifest.xsd");

What am I doing wrong here?

6
  • here the difference is: mf:mf="urn:x-lexisnexis:content:manifest:global:1" this is required. and I am getting: xmlns:mf="urn:x-lexisnexis:content:manifest:global:1" Commented Apr 2, 2021 at 17:08
  • 2
    Your desired XML is not well-formed. Upload it to xmlvalidation.com and you will get an error, Errors in the XML document: 1: 250 The prefix "mf" for element "mf:package" is not bound. Specifically, you define an element <mf:package ... but never associate the mf prefix to a namespace. mf:mf=".." is not the correct way to do that. xmlns:mf=".." is the correct way, i.e. XmlWriter fixed it for you automatically. (That is, unless your XML is a fragment of some larger document that does define the mf namespace.) Commented Apr 2, 2021 at 17:13
  • 1
    @dbc: Your comment could be an answer, IMHO. Commented Apr 2, 2021 at 17:26
  • <mf:package xmlns="urn:x-lexisnexis:content:manifest:global:1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:x-lexisnexis:content:manifest:global:1 sch_manifest.xsd" mf:mf="urn:x-lexisnexis:content:manifest:global:1"> <mf:metadata allOrNone="0" contentProviderID="KM_SEC_CONTENT" contentProviderIDScheme="Knowledge Mosaic ID" id="abc"> <mf:dataFiles mf:mf="urn:x-lexisnexis:content:manifest:global:1"> Commented Apr 2, 2021 at 17:32
  • more of the content which is required ^^ Commented Apr 2, 2021 at 17:33

1 Answer 1

1

Assuming you are writing the root XML element, your desired XML is not well-formed:

<mf:package 
   xmlns="urn:x-lexisnexis:content:manifest:global:1" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation="urn:x-lexisnexis:content:manifest:global:1 sch_manifest.xsd" 
   mf:mf="urn:x-lexisnexis:content:manifest:global:1"> <!--mf:mf is not correct -->

Upload it to https://www.xmlvalidation.com/ and you will get an error,

Errors in the XML document: 1: 250 The prefix "mf" for element "mf:package" is not bound.

Specifically, you define an element <mf:package ... but never associate the mf prefix to a namespace. mf:mf="..." is not the correct way to do that. Instead, a namespace declaration attribute must either be xmlns or begin with xmlns:, so xmlns:mf="..." is the correct way:

<mf:package 
   xmlns="urn:x-lexisnexis:content:manifest:global:1" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation="urn:x-lexisnexis:content:manifest:global:1 sch_manifest.xsd" 
   xmlns:mf="urn:x-lexisnexis:content:manifest:global:1">  <!--Corrected -->

Since this is the XML you are actually getting, XmlWriter generated well-formed XML for you automatically.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.