Return Type | Function name | Arguments |
---|---|---|
hzEcode | hzDocXml::Load | (hzChain&,) |
Declared in file: hzDocument.h
Defined in file : hzDocXml.cpp
Function Logic:
Function body:
hzEcode hzDocXml::Load (hzChain& Z) { _hzfunc("hzDocXml::Load") ; hzList<hzString>::Iter exI ; std::ifstream is ; hzChain::Iter ci ; hzChain::Iter xi ; hzChain nodeContent ; hzXmlNode* pCN = 0; hzXmlNode* pNN ; hzString Test ; hzString tagval ; uint32_t tagstate ; bool bNewline ; hzEcode rc = E_OK ; m_Error.Clear() ; ci = Z ; for (; *ci & 0x80;ci++); if (ci == "<?xml") { for (ci++ ; *ci != CHAR_MORE ; ci++) ; for (ci++ ; *ci <&eq; CHAR_SPACE ; ci++) ; } if (ci.Equiv("<!doctype")) { for (ci += 9; *ci && *ci <&eq; CHAR_SPACE ; ci++) ; tagstate = 1; for (; tagstate && *ci ; ci++) { if (*ci == CHAR_LESS) tagstate++ ; if (*ci == CHAR_MORE) tagstate-- ; } } /* ** ** Process document ** */ bNewline = true ; for (; !ci.eof() ;) { if (*ci == CHAR_CR) ci++ ; if (*ci == CHAR_NL) { bNewline = true ; ci++ ; continue ; } if (bNewline) { if (pCN && nodeContent.Size()) nodeContent.AddByte(CHAR_NL) ; bNewline = false ; } if (!pCN) { if (*ci != CHAR_LESS) { m_Error.Printf("File %s Line %d: Encountered char (%c:%d) outside scope of any tag\n", *m_Filename, ci.Line(), *ci, *ci) ; rc = E_SYNTAX ; break ; } } if (*ci == CHAR_LESS) { if (ci == "<!--") { for (ci += 4; !ci.eof() ; ci++) { if (*ci == CHAR_MINUS && ci == "-->") break ; } if (ci.eof()) { m_Error.Printf("File %s Line %d: HTML comment block begins which is not terminated\n", *m_Filename, ci.Line()) ; rc = E_SYNTAX ; break ; } ci += 3; continue ; } if (ci == "<![CDATA[") { xi = ci ; for (xi += 9; !xi.eof() ; xi++) { if (xi == "]]>") { xi += 3; ci = xi ; break ; } nodeContent.AddByte(*xi) ; } pCN->SetCDATA(nodeContent) ; nodeContent.Clear() ; continue ; } if (m_bXmlesce) { if (_testHtag(tagval, ci)) { nodeContent << *tagval ; ci += tagval.Length() ; continue ; } } if (pCN && pCN->IsXmlesce()) { if (_testHtag(tagval, ci)) { threadLog("m_bXmlesce is on node=%s\n", *tagval) ; nodeContent << *tagval ; ci += tagval.Length() ; continue ; } } /* ** ** Handle tag open ** */ tagstate = _proctagopen(&pNN, pCN, ci) ; if (tagstate < 0) { m_Error.Printf("File %s Line %d: Bad tag format\n", *m_Filename, ci.Line()) ; break ; } if (tagstate == 0) { if (pNN) { if (nodeContent.Size()) pNN->SetPretext(nodeContent) ; nodeContent.Clear() ; pCN = pNN ; if (!m_pRoot) { m_pRoot = pNN ; } m_NodesName.Insert(pNN->txtName(), pNN->GetUid()) ; } ci++ ; continue ; } if (tagstate == 1) { if (pNN) { if (nodeContent.Size()) pNN->SetPretext(nodeContent) ; nodeContent.Clear() ; if (!m_pRoot) { m_pRoot = pNN ; } m_NodesName.Insert(pNN->txtName(), pNN->GetUid()) ; } ci++ ; continue ; } rc = E_OK ; /* ** ** Handle tag close ** */ if (_istagclose(Test, ci)) { if (Test != pCN->txtName()) { m_Error.Printf("File %s Line %d: Mismatched XML tags: Current <%s> line %d closing <%s>", *m_Filename, ci.Line(), pCN->txtName(), pCN->Line(), *Test) ; rc = E_FORMAT ; break ; } if (nodeContent.Size()) pCN->SetContent(nodeContent) ; nodeContent.Clear() ; pCN->_setanti(ci.Line()) ; pCN = pCN->Parent() ; if (pCN == 0) break ; ci++ ; continue ; } } if (pCN == 0) break ; if (*ci == CHAR_TAB) nodeContent.AddByte(CHAR_SPACE) ; else nodeContent.AddByte(*ci) ; ci++ ; } if (pCN) { m_Error.Printf("File %s Line %d: End of file encountered whilst inside tag definition\n", *m_Filename, ci.Line()) ; rc = E_FORMAT ; } return rc ; }