开发者

can open xml sdk be used in creating xml files?

开发者 https://www.devze.com 2023-01-28 23:12 出处:网络
is it possible to use the OPEN XML SDK and generate an xml file that contains some metadata of a particular docx file?

is it possible to use the OPEN XML SDK and generate an xml file that contains some metadata of a particular docx file?

details: i have a docx file, from w开发者_运维技巧hich i want to extract some metadata(using open xml) and display them as xml file and later use Jquery to present them in a more readable form.


You can use the SDK to extract info from the various properties parts which may be present in the docx (for example, the core properties part, which included dublin core type info).

You can extract it in its native XML form:

    <cp:coreProperties          
            xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-                    properties" 
            xmlns:dc="http://purl.org/dc/elements/1.1/" .. >
       <dc:creator>Joe</dc:creator>
       <cp:lastModifiedBy>Joe</cp:lastModifiedBy>
       <cp:revision>1</cp:revision>
       <dcterms:created xsi:type="dcterms:W3CDTF">2010-11-10T00:32:00Z</dcterms:created>
       <dcterms:modified xsi:type="dcterms:W3CDTF">2010-11-10T00:33:00Z</dcterms:modified>
   </cp:coreProperties>

or, in some other XML dialect of your own choosing.


I know question was posted a long time ago, but first result of google search sent me here. So if there are others looking for a solution to this, there is a snippet on MSDN website https://msdn.microsoft.com/en-us/library/office/cc489219.aspx

short answer is... using XmlTextWritter, and it applies to Office 2013 afaik:

// Add the CoreFilePropertiesPart part in the new word processing document.
var coreFilePropPart = wordDoc.AddCoreFilePropertiesPart();
using (XmlTextWriter writer = new XmlTextWriter(coreFilePropPart.GetStream(FileMode.Create), System.Text.Encoding.UTF8))
{
    writer.WriteRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\"></cp:coreProperties>");
    writer.Flush();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消