XMLDocument Namespace (Präfix) Änderung



  • Hallo Zusammen,
    Ich versuche seit einer weile ein spreadsheet von OpenOffice mit XMLDocument einzulesen. Scheitere immer an der Stelle wo sich der Präfix(Namespace) von office in table(nxmlCell) ändert!! Bei nlxmlSpreadSheet ist noch alles ok. Wenn ich den Präfix von table -> office im XML ändere geht es auch. Muss ich den Namespace hier neu definieren oder wo liegt der Fehler??

    Ich benutze CodeGear™ C++Builder® 2007 R2 Version 11.0.2804.9245

    Danke für eure Hilfe im Voraus

    Hier meine bisherige Abfrage:

    //dec
    AnsiString asFileName = MyDocumentsDataPath()+"\\tmp\\";
    IXMLNodeList *nlxmlAttribute,*nlxmlRow;
    IXMLNodeList *nlxmlTable,*nlxmlSpreadSheet,*nlxmlBody,*nlxmlRoot;
    IXMLNode *nxmlCell, *nxmlText,*nxmlTextType;
    //prg
    	XMLDoc->LoadFromFile(asFileName+CONTENT_XML);
    	nlxmlRoot=XMLDoc->DocumentElement->ChildNodes;
    	nlxmlBody = nlxmlRoot->GetNode("office:body")->ChildNodes;
    	nlxmlSpreadSheet = nlxmlBody->GetNode("office:spreadsheet")->ChildNodes;
    	nxmlCell =   nlxmlSpreadSheet->GetNode("table:table");
    	Panel1->Caption=nxmlCell->AttributeNodes->GetNode("table:style-name")->GetNodeValue();
    

    Hier noch das XML:

    <?xml version="1.0" encoding="UTF-8" ?> 
    - <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:\1:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" office:version="1.2" grddl:transformation="http://docs.oasis-open.org/office/1.2/xslt/odf2rdf.xsl">
      <office:scripts /> 
    - <office:font-face-decls>
      <style:font-face style:name="Arial1" svg:font-family="Arial" /> 
      <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable" /> 
      <style:font-face style:name="Lucida Sans Unicode" svg:font-family="'Lucida Sans Unicode'" style:font-family-generic="system" style:font-pitch="variable" /> 
      <style:font-face style:name="SimSun" svg:font-family="SimSun" style:font-family-generic="system" style:font-pitch="variable" /> 
      <style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-family-generic="system" style:font-pitch="variable" /> 
      </office:font-face-decls>
    - <office:automatic-styles>
    - <style:style style:name="co1" style:family="table-column">
      <style:table-column-properties fo:break-before="auto" style:column-width="2.166cm" /> 
      </style:style>
    - <style:style style:name="ro1" style:family="table-row">
      <style:table-row-properties style:row-height="0.453cm" fo:break-before="auto" style:use-optimal-row-height="true" /> 
      </style:style>
    - <style:style style:name="ta2" style:family="table" style:master-page-name="PageStyle_5f_Tabelle2">
      <style:table-properties table:display="true" style:writing-mode="lr-tb" /> 
      </style:style>
    - <style:style style:name="ta3" style:family="table" style:master-page-name="PageStyle_5f_Tabelle3">
      <style:table-properties table:display="true" style:writing-mode="lr-tb" /> 
      </style:style>
    - <style:style style:name="ta4" style:family="table" style:master-page-name="PageStyle_5f_Tabelle1">
      <style:table-properties table:display="true" style:writing-mode="lr-tb" /> 
      </style:style>
    - <number:number-style style:name="N2">
      <number:number number:decimal-places="2" number:min-integer-digits="1" /> 
      </number:number-style>
      <style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N2" /> 
    - <style:style style:name="ta_extref" style:family="table">
      <style:table-properties table:display="false" /> 
      </style:style>
      </office:automatic-styles>
    - <office:body table:test="wau">
    - <office:spreadsheet table:test2="wau2">
      <office:calculation-settings table:case-sensitive="false" table:automatic-find-labels="false" table:use-regular-expressions="false" /> 
    - <table:table table:name="Tabelle1" table:style-name="ta4" table:print="false">
      <office:forms form:automatic-focus="false" form:apply-design-mode="false" /> 
      <table:table-column table:style-name="co1" table:number-columns-repeated="1024" table:default-cell-style-name="ce1" /> 
    - <table:table-row table:style-name="ro1">
    - <table:table-cell office:value-type="float" office:value="45.59">
      <text:p>45,59</text:p> 
      </table:table-cell>
    - <table:table-cell office:value-type="float" office:value="23">
      <text:p>23,00</text:p> 
      </table:table-cell>
      <table:table-cell table:number-columns-repeated="1022" /> 
      </table:table-row>
    - <table:table-row table:style-name="ro1">
    - <table:table-cell office:value-type="float" office:value="32">
      <text:p>32,00</text:p> 
      </table:table-cell>
      <table:table-cell table:number-columns-repeated="1023" /> 
      </table:table-row>
    - <table:table-row table:style-name="ro1" table:number-rows-repeated="65533">
      <table:table-cell table:number-columns-repeated="1024" /> 
      </table:table-row>
    - <table:table-row table:style-name="ro1">
      <table:table-cell table:number-columns-repeated="1024" /> 
      </table:table-row>
      </table:table>
    - <table:table table:name="Tabelle2" table:style-name="ta2" table:print="false">
      <table:table-column table:style-name="co1" table:number-columns-repeated="1024" table:default-cell-style-name="Default" /> 
    - <table:table-row table:style-name="ro1">
      <table:table-cell table:number-columns-repeated="1024" /> 
      </table:table-row>
      </table:table>
    - <table:table table:name="Tabelle3" table:style-name="ta3" table:print="false">
      <table:table-column table:style-name="co1" table:number-columns-repeated="1024" table:default-cell-style-name="Default" /> 
    - <table:table-row table:style-name="ro1">
      <table:table-cell table:number-columns-repeated="1024" /> 
      </table:table-row>
      </table:table>
      </office:spreadsheet>
      </office:body>
      </office:document-content>
    


  • Hast du mal den XML-Datenbindungs-Wizard ausprobiert? Der nimmt dir das Rumprobieren ab.



  • Danke für den Tipp!!
    Hab es probiert und nun hab ich zwei Fragen dazu.

    1. Er sagt mit immer beim erstellen, das der Dokumentelementtyp nicht angegeben wurde. Weiß garnicht wo man den eingeben kann. Irgendeine Idee?
    2. Hat jemand vielleicht ein kleines Beispiel wie ich in c++ die erzeugte Unit nutzen kann. Da hier alle tutorials aufhören aber ich genau da nicht weiter komme.

    Besten Dank



  • Am weitesten kommst du, wenn du einfach die generierte Headerdatei liest. Für den Start habe ich hier mal ein Beispiel geschrieben, das könnte auch hilfreich sein.


Anmelden zum Antworten